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
Answer Posted / ramse
One way is:
function swap($x, $y) {
$x ^= $y ^= $x ^= $y;
return array($x,$y);
}
| Is This Answer Correct ? | 2 Yes | 5 No |
Post New Answer View All Answers
How to Retrieve the Session ID of the Current Session?
How to remove blank spaces from the string?
What is difference between Method overriding and overloading in PHP?
What version of php do I have windows?
Why namespace is used in php?
How stop the execution of a php scrip?
Do you know what is the function func_num_args() used for?
What does the unlink() function means?
What are the types of variables in php?
Define anonymous classes in php7?
Which function would you use to read a line of data from a file in php?
Explain what is the difference between $var and $$var?
What are the design patterns in php?
What advance thing in php7?
How do you parse and process html/xml in php?