- print_r: documentation ( source)
<?php
function removeSomeElements(&$arr)
{
for ($i = 0; $i<count($arr); $i++) {
$c = $arr[$i];
if ($c > 2) {
echo "Element $c found at $i\n";
unset($arr[$i]);
}
}
print_r($arr); // misses middle element
return true;
}
$t = [0, 3, 1];
print_r($t); // original array
$success = removeSomeElements($t);
print_r($t); // should be missing middle element, but everything is here