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



1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u c..

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

1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u c..

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

1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u c..

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

1. Write a function to swap two values ? $a = 10; $b = 20; echo $a, $b; swap(); // If u want u c..

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

Post New Answer

More PHP Interview Questions

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?

0 Answers  


Is PHP an open source software?

0 Answers  


How can you propagate a session id?

0 Answers  


What is a base url?

0 Answers  






What are the methods to submit form in php?

0 Answers  


What is different types of visibility?

0 Answers  


Where sessions stored in PHP?

0 Answers  


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

2 Answers  


What is php and why it is used?

0 Answers  


Write down the code for saving an uploaded file in PHP.

0 Answers  


Is it difficult to learn php?

0 Answers  


Categories