➤ By default, PHP variables are passed by value as the function arguments in PHP. When variables in PHP is passed by value, the scope of the variable defined at function level bound within the scope of function. Changing either of the variables doesn’t have any effect on either of the variables. ➤ When variables are passed by reference, use & (ampersand) symbol need to be added before variable parameter. For example: function( &$x ). Scope of both global and function variable becomes global as both variables are defined by same reference. Therefore, whenever global variable is change, variable inside function also gets changed. For instance:
function print_string( &$str ) {
    $str = " PHP \n";
    print( $str );
}
$string = " JS \n";
print_string( $string ); // outputs:  PHP
print( $string ); // outputs:  PHP
by Levani Makhareishvili
2 years ago
PHP
References
1
Pro tip: use ```triple backticks around text``` to write in code fences