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

Does browser understand php?

492


How to open a file for writing?

566


How do I debug php?

530


what is mean by portal

1466


Tell me how can we check the value of a given variable is alphanumeric?

497






Write a statement to show the joining of multiple comparisons in php?

536


What is split function in php?

512


Write logic to print Floyd's triangle in PHP?

546


What is the Default syntax used in PHP?

600


What is a http session?

548


Which functions are used to remove whitespaces from the string?

617


What is x+ mode in fopen() used for?

561


What is the difference between mysql_fetch_array() and mysql_fetch_assoc()?

524


How to pass variables by references?

558


Explain what does $_files means?

560