I did something like this today:
-
<?php
-
-
if(true) // for sake of clarity
The loop never came to the final element of the array, therefore not checking all of them. What was the problem?
Since sizeof($arr) is calculated every time the loop comes around, it was returning less and less with every unset instead of returning the same value.
Solution:
-
<?php
-
-
-
for($i = 0; $i < $size; $i++)
-
if(true) // for sake of clarity
That way you ensure that size is always the correct integer. And it will run faster.

You could also go with foreach ($arr as $i => $value) unset($arr[$i]);
Yes, indeed. Don’t know why that didn’t occur to me. Must be the “late” hours.