You would also need a
$i--;
after each unset to not skip an element/
Because when you unset $item[45]
, the next element in the for-loop should be $item[45]
- which was [46]
before unsetting. If you would not do this, you'd always skip an element after unsetting.