PHP Call By Value
PHP allows you to call the function by value and reference both. In the case of PHP call by value, the actual value is not modified if it is modified inside the function.
Concept of the call by value by the help of examples.
PHP Call By Value Example 1
variable $str is passed to the adder function where it is concatenated with Call By Value string. But, printing $str variable results Hello only. It is because changes are done in the local variable $str2 only. It does not reflect to $str variable.
<?php
function adder($str2)
{
$str2 .= "Call By Value";
}
$str = "Hello";
adder($str);
echo $str;
?>
Output: Hello
PHP Call By Value Example 2
<?php
function increment($i)
{
$i++;
}
$i = 10;
increment($i);
echo $i;
?>
Output: 10
Series:
PHP Tutorials Hub
