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 |
Where is the submitted form data stored?
Explain the difference between unlink() and unset()?
How to find a length of a string in php?
What are the security measures we have to take for our site not to hack by others.
3 Answers Infosys, Torque Infotech,
What are escaping characters? Explain with an example?
What is data structure in php?
how to add file in php?
Is laravel frontend or backend?
How can we change the value of a constant?
What is laracast?
Explain what is the difference between $var and $$var?
What is curl php?