<?php
define('MAX_LOOPS',5);
function withRefValue($elements, $transform) {
for ($i=0; $i<$elements; $i++) {
$a[] = "v.$i";
}
$counter=0;
foreach ($a as $k=>&$v) {
eval($transform);
$counter++;
if ($counter>MAX_LOOPS) {
break;
}
}
echo "--> State of array after loop:\n";
var_dump($a);
}
echo "\nPopping elements off end of an unreferenced array, using &\$value.";
$transform = 'array_pop($a);';
withRefValue(1, $transform);
withRefValue(2, $transform);
withRefValue(3, $transform);
withRefValue(4, $transform);
withRefValue(5, $transform);
withRefValue(6, $transform);
withRefValue(7, $transform);
withRefValue(8, $transform);
preferences:
34.77 ms | 402 KiB | 5 Q