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 / binoyav

$a = 10;
$b = 20;

echo $a, $b;
echo "<br>";
swap($a, $b);
echo $a, $b;
function swap(&$a, &$b)
{
$temp = $a;
$a = $b;
$b = $temp;
}

Is This Answer Correct ?    79 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between $var and $$var?

562


Why php is widely used?

555


What's the difference between __sleep and __wakeup?

554


What are the rules in creating php variable?

537


How do I see how many pages per session in google analytics?

532






Which is better session or cookie?

537


What is the scope of a variable defined outside a function?

548


What are soundex() and metaphone() functions in php?

486


Is php better than java?

552


How to get the ip address of the client?

8708


Is php used for frontend or backend?

536


What is difference between isset and empty in php?

544


What is the use of strpos in php?

567


How to test if a variable is an array?

570


In how many ways we can retrieve the data in the result set of mysql using php?

501