Thursday, September 7, 2017

PHP Call By Value


PHP allows you to call function by value and reference both. In this article I want to discuss about PHP call by value, actual value is not modified if it is modified inside the function.

Let's see the concept of call by value by the help of below examples.

Example - 1 :
<?php  
function concatString($str2)  
{  
    $str2 .= 'Call By Value';  
    echo "$str2"."<br/>" ;
}  
$str = 'Demo  ';  
concatString($str);  
echo $str;  
?>
Output :
-----------------------------
Demo Call By Value
Demo

Example -2 :
<?php  
function increment($i)  
{  
    $i++;  
    echo "Inside function :  $i <br/>";
}  
$i = 10;  
increment($i);  
echo "Outside Function : ".$i;  
?>


Output :
-------------------
Inside function : 11 
Outside Function : 10



No comments:

Post a Comment