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
What are the two types of variables?
How to find a substring from a given string in php?
What is the difference between overloading and overriding in php?
How big is nvarchar max?
What are the benefits of using queries?
Which is better php or nodejs?
What is the difference between php traits vs interfaces?
Explain include(), include_once, require() and require_once?
Is age nominal or ordinal?
What is uniqid php?
Explain whether it is possible to share a single instance of a memcache between multiple php projects?
How long will it take to learn php?
Tell me how can we automatically escape incoming data?
What is php mean?
Is salary a ratio or interval?