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
What is the use of rand() in php?
What are getters and setters php?
Can we override magic methods in php?
How to get the number of characters in a string?
How to remove leading and trailing spaces from user input values?
What is the sign to start variables in PHP?
Are static variables final?
how can i develop forum code? any one pleale help me on this question
How do I check environment variables?
Does php 7 support multiple inheritance?
What is the purpose of the '.frm' file extension? What do thes file contain?
What is isset in php?
What is php array function?
How to block direct directory access in PHP?
how to detect a mobile device using php