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


Please Help Members By Posting Answers For Below Questions

What is php trait?

516


Tell me what should we do to be able to export data into an excel file?

519


What is stripslashes php?

509


How long does a session last in php?

510


What is advanced php programming?

532






Which is the dependent variable?

485


I need to know about the courses which are useful in corporate companies.. especially php/mySQL, Java/j2ee, .NET.. also tell if any other courses are valuable

1514


How to open standard output as a file handle?

560


What is the use of count() function in php?

526


Do you know what is the difference between mysql_fetch_object() and mysql_fetch_array()?

520


What is difference between static and constant in php?

498


What are the functions to be used to get the image's properties (size, width and height)?

544


How can we connect to a mysql database from a php script?

527


How can we automatically escape incoming data?

533


Write a program in php to check whether a number is prime or not?

494