Wednesday 18 December 2013

Call by refrence in PHP

Following example show orignal value of parameter change.
<?php
function orignalValueChange(&$refParameter)
{
    $refParameter = 4;
  
}
$var = 23;
orignalValueChange($var);
echo $var;

?>
output:
4
Following example show orignal value of parameter not change.

<?php
function orignalValuenotChange($refParameter)
{
    $refParameter = 4;
  
}
$var = 23;
orignalValuenotChange($var);
echo $var;

?>
output:
23

Example

<?php
function callbyref(&$para1, &$para2,&$para3)
{ $para1 = $para2 = $para3;
}
$var1 = 1000;
$var2 = 2000;
$var3 = 3000;
callbyref($var1, $var2,$var3);
$var2 = 5;
echo "<br/>";
echo $var1;

?>
output:
 3000

No comments:

Post a Comment