Friday, May 18, 2018

Access by reference

Function returning reference

$r = 10;
$ref = & funcByRef("r");
$ref = 12;
print $r;
function &funcByRef($v) {
 return $GLOBALS[$v];   
}
Output:
12

Function Parameter - access by reference

$r = 10;
funcByRefParam($r);
print $r;
function funcByRefParam(&$v) {
 $v--;
}
Output:
9

No comments:

Post a Comment

here docs

$x = <<<THE_END PHP stands for "PHP: Hypertext Preprocessor". The acronym "PHP" is therefore, usually referre...