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 is local variable in php?
What is difference between strstr() and stristr()?
What is a definer in mysql?
What is exception handling in php?
What is a php form?
How could I install codeignitor ?
Explain the changes in php versions?
How to enable cURL in PHP?
What is the default time of cookie in php?
Is php 5.6 secure?
Explain the difference between $var and $$var?
How to write a program to make chess?
Tell me is it possible to remove the html tags from data?
Is php object oriented?
What is reference variable php?