Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 / ankush sharma

<?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 ?    14 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of rand() in php?

1091


What are getters and setters php?

1075


Can we override magic methods in php?

1063


How to get the number of characters in a string?

1078


How to remove leading and trailing spaces from user input values?

1023


What is the sign to start variables in PHP?

1160


Are static variables final?

1051


how can i develop forum code? any one pleale help me on this question

1989


How do I check environment variables?

1052


Does php 7 support multiple inheritance?

1084


What is the purpose of the '.frm' file extension? What do thes file contain?

1014


What is isset in php?

1052


What is php array function?

1245


How to block direct directory access in PHP?

1023


how to detect a mobile device using php

1138