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 / ankush sharma
<?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 ? | 14 Yes | 2 No |
Post New Answer View All Answers
What are the final class and final method?
What is $_ post in php?
What is Type hinting in PHP?
Explain me what is the use of header() function in php?
How to generate a character from an ascii value?
What u mean by query?
How to initiate a session in php?
How can i execute PHP File using Command Line?
What language is similar to php?
How you can update memcached when you make changes to php?
Tell me how is it possible to return a value from a function?
Tell me how do you execute a php script from the command line?
What are the differences between php constants and variables?
What is difference between get and post?
What is constructor and destructor?