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 |
How can I embed a java programme in PHP file and what changes have to be done in PHP.ini file?
1 Answers Sify, Small Biz Express,
What does the function get_magic_quotes_gpc() means?
Is PHP an open source software?
How can you propagate a session id?
What is a base url?
What are the methods to submit form in php?
What is different types of visibility?
Where sessions stored in PHP?
can any one tell how to install LAMP server in terminal in ubuntu.....and also tell please how to run php files in ubunut and how to save and compile in ubuntu..i already installed ubuntu ..but i dont installed lamp server so i want to install lamp server in terminal is it possible please reply
What is php and why it is used?
Write down the code for saving an uploaded file in PHP.
Is it difficult to learn php?