<?php
$a = 1; $b = &$a; $b = 42; print $a;
This is pretty simple, isn't it?
Output: 42.
<?php
$array = array_reverse(range(1, 42));
foreach ($array as &$value) {
// do nothing;
}
$array = array_reverse($array);
foreach ($array as $value) {
// do nothing;
}
print reset($array);
This isn not that obvious, isn't it?
Output: 42.
What about closures?
<?php
$param = 666;
function meaningOfLife() {
$param = 1;
$func = function() use(&$param) {
$param = 42;
};
$func();
print $param;
}
meaningOfLife();
Output: 42.