Pass by reference in PHP

In PHP you can pass a variable to a function as reference. When you do that actual “Memory address is passed” instead of “A Copy of the value” hence any change you make inside the function will reflect even after the outside after the function is executed.


function change( &$fruit ){

	$fruit = 'Guva';

$fruit = 'apple';
echo 'Before call: ' . $fruit;
change( $fruit );
echo 'After call : ' . $fruit;


You give & (ampersand) before the variable name in the function signature only and not in the function call.