foreach
iterates over the array and assigns the key to $i and the value to $a before accessing the code block inside the loop. The array is actually "copied" by the function before being iterated over, so any changes to the original array does not affect the progression of the loop.
You can also pass the $array by reference into the foreach using $i => &$a
instead of by value which will allow the mutation of the array.
Another option would be to work directly on the array, and you would see something different:
for($x=0;$x<count($array);$x++){
unset($array[1]);
// for $x=1 this would result in an error as key does not exist now
echo $array[$x];
}
print_r($array);
Of course, this assumes that your array is numerically and sequentially keyed.