1. Write a function to swap two values ?
$a = 10;
$b = 20;
echo $a, $b;
swap(); // If u want u can pass parameters
echo $a, $b; // It should print 20 , 10
Answers were Sorted based on User's Feedback
Answer / ajay
I checked the answer posted by Sunil. This answer is
correct,the only mistake he did that the program print the
output together as 1020,2010,not like this
10
20
20
10
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / meenakshisundaram
$a = 10;
$b = 20;
echo $a, $b;
swap();
echo $a, $b;
swap(){
list($a, $b) = array($b, $a);
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sangita jain
<?php function swap(){
$a=10;
$b=20;
$b=$b-$a;
$a=$a+$b;
echo $a,$b;
}
swap();
?>
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / ramse
One way is:
function swap($x, $y) {
$x ^= $y ^= $x ^= $y;
return array($x,$y);
}
| Is This Answer Correct ? | 2 Yes | 5 No |
How do you connet mysql database with php?
What is class extend in php?
hi i am complted my b.tech and i want to learn php is php is good for my career and i want to know the salary growth on php any one can tell the answer plz and i am learning php myself it is easy to understand..........
hello myself Atul saini completed mca in 2007 due to personal problem i cant do job.now i really search 4 a job.i dont know where i go i think simple think is learn php anyone help me wat i can do for a job. thanks
What is the timeout period on session values?
What is php session_start() and session_destroy() function?
how can we check mail function with '127.0.0.1' (before submitting a site?
What is the super method?
Why do we create an instance of a class in php?
Is php 5.6 secure?
Why do you need to filter out empty files?
How do you destroy a session?