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 / vivek srivastava
<?php
$a=10;
$b=20;
echo $a,$b;
echo "<br>";
swap($a, $b);
echo "<br>";
echo $a,$b;
function swap(&$a, &$b)
{
$a = $a + $b;
$b = $a - $b;
$a = $a - $b;
}
?>
| Is This Answer Correct ? | 31 Yes | 8 No |
Post New Answer View All Answers
How do you find the length of a string in php?
How we can declare variable in php?
What is the difference between pop3 IMAP and MAPI?
Tell me how is the ternary conditional operator used in php?
What is the definition of a session?
What is the difference between "echo" and "print" in php?
Describe PHP error and logging information?
How do I get csrf token?
Why is overriding runtime?
Does apache use php?
Why shouldn't I use mysql_* functions in php?
What is session data?
What is difference between post and put in rest?
What is use of header() function in php? What the limitation of header()?
Explain the difference between urlencode and urldecode?