PHP Call By Reference

 






PHP Call By Reference:

So, whenever you want to recieve arguments by reference, varibale must be prefixed by & symbol. It acutally makes reference to variables for calling the function. See the example below:

<?php  
function add(&$x)  
{  
    $x .= 'Call By Reference';  
}  
$y = ' Exanple of ';  
add($y);  
echo $y;  //concate two string using call by reference
?>  

Result will be: Exanple of Call By Reference

see another example:

<?php  
function add(&$x)  
{  
    $x--;  
}  
$y = 5;  
add($y);  
echo $y;  //decrement using call by reference
?>  

Post a Comment (0)
Previous Post Next Post