Php program for the passing arguments by reference

A php program for the passing arguments by reference. By reference, pass Passing the reference of an argument in the calling function to the corresponding formal parameter of the called function, also known as pass by address, involves making a copy of the address of the real parameter in memory, where the caller and the called utilize the same parameter variable.

<?php
function add(&$value)
{
$value += 5;
}

$num = 2;
add($num);
echo $num;
?>

 

Output:

7

What is passing arguments by reference in php program

The term “pass-by-reference” refers to passing the reference of a calling function argument to the corresponding formal parameter of the called function. The called function can change the value of the argument by using the reference passed in. How to pass arguments by reference is demonstrated in the following example. 

When passing variables by reference, use the & (ampersand) symbol before the variable argument. For instance, function(&$x ). Because both the global and function variables are defined by the same reference, their scope becomes global.