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
How many different types of messages available in php?
Which is faster for or foreach php?
Explain me what is the use of 'print' in php?
How do I run a php script in windows?
What is the goto statement useful for?
Explain briefly about a search-friendly site looks like?
How to remove the new line character from the end of a text line?
How do you end a session in php?
Explain what is the static variable in function useful for?
What are php strings?
What is difference between include,require,include_once and require_once()?
List some of the features of php7.
What is the different between count() and sizeof() in php?
Explain setcookie() function in php?
What is scope of variable in php?