Home Tutorial Php Phpbasics Tutorial PHP Call By Reference

 
 

Share on Google+Share on Google+
PHP Call By Reference
Posted on: February 22, 2010 at 12:00 AM
Advertisement
In this tutorial we will study about call by reference, in which we pass the reference of the variable and modify the values inside another function.

PHP Call By Reference:

In PHP we can pass reference of a variable, so that we can modify the variable's value inside another function and get the modified values from where we have sent. It is much like the call by reference, in which we send the base address of the variable and we modify the values inside another function.

PHP Call By Reference Example:

<?php

function swap(&$a,&$b){

$a+=$b;

$b=$a-$b;

$a=$a-$b;

}

$var1=34;

$var2=90;

echo "<b>Before swapping values are \$var1= $var1 & \$var2= $var2 <br/> </b>";

swap($var1,$var2);

echo "<b>After swapping values are \$var1= $var1 & \$var2= $var2 <br/></b>";

?>

Output:

Before swapping values $var1= 34 & $var2= 90
After swapping values $var1= 90 & $var2= 34

 

Advertisement

Related Tags for PHP Call By Reference:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 22, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com