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
Answers were Sorted based on User's Feedback
Answer / ajay
I checked the answer posted by Sunil. This answer is
correct,the only mistake he did that the program print the
output together as 1020,2010,not like this
10
20
20
10
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / meenakshisundaram
$a = 10;
$b = 20;
echo $a, $b;
swap();
echo $a, $b;
swap(){
list($a, $b) = array($b, $a);
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sangita jain
<?php function swap(){
$a=10;
$b=20;
$b=$b-$a;
$a=$a+$b;
echo $a,$b;
}
swap();
?>
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / ramse
One way is:
function swap($x, $y) {
$x ^= $y ^= $x ^= $y;
return array($x,$y);
}
| Is This Answer Correct ? | 2 Yes | 5 No |
am from coimbatore.am learning php&mysql. what will be the approx salary for me if i get a job in coimbatore.
What is singleton class in php?
write the prime number of program?in php
What is the difference between get and post method in php?
What is the different between count() and sizeof() in php?
Where are php configuration settings stored?
Do you know what does $globals means?
Difference between $message vs. $$Message in php.
What are the uses of explode() and implode() functions?
How do you develop your own PHP extension ?
Explain what is the difference between mysql_fetch_array() and mysql_fetch_assoc()?
Does strlen include null?