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 to check an element is exists in array or not in php?
What is session_start () in php?
How to display your correct URL of the current web page?
What is phpsessid?
What is the function of trim?
What's the difference between accessing a class method via -> and via ::?
Is multiple inheritance supported in php?
Explain the difference between php4 and php5.
What is the role of php?
Write a program to swap two numbers using php.
Is php a programming language?
What is htmlentities function in php?
Explain the three different kinds of Arrays?
How does the identity operator ===compare two values in PHP?
What is the meaning of a persistent cookie?