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
How to convert a string to lowercase in php?
How can I load data from a text file into a table?
What is cakephp framework?
Code to upload a file in PHP?
What is a php tag?
Why php was called as personal home page?
How does api connect to database?
Explain about PHP filter and why it should be used?
What is the use of die in php?
What are form input html tags?
How arrays are used in php?
Why do we use hooks?
How to avoid the undefined index error?
How to access a Static Member of a Class in PHP?
Why do you need php?