php - what is the value of $a and $b after the function call and why? (pass by reference and pass by value) -
what value of $a , $b after function call , why?
just clarify difference between pass reference
, pass value
function dosomething( &$arg ) { $return = $arg; $arg += 1; return $return; } $a = 3; $b = dosomething( $a );
$a 4
$b 3
the former ($a
) because $arg
passed reference, latter ($b
) because return value of function copy of (not reference to) initial value of argument.
Comments
Post a Comment