WARNING: unset($array[$element]) is not an efficient way to delete the element in an array. What that does is simply set its value to null. It's not like a linked list that will actually remove the element. Run this code and you'll see:
<?
$ar = array("this","that","foo","bar","the other");
$s=sizeof($ar);
for($i=0;$i<$s;$i++)
print "ar[$i] = " .$ar[$i]."\n";
unset($ar[1]);
print "\n";
for($i=0;$i<$s;$i++)
print "ar[$i] = " .$ar[$i]."\n";
?>
OUTPUT:
ar[0] = this
ar[1] = that
ar[2] = foo
ar[3] = bar
ar[4] = the other
ar[0] = this
ar[1] =
ar[2] = foo
ar[3] = bar
ar[4] = the other
If I had not done $s=sizeof($ar), and instead just used sizeof($ar) in the for loop, the output would look like this:
ar[0] = this
ar[1] = that
ar[2] = foo
ar[3] = bar
ar[4] = the other
ar[0] = this
ar[1] =
ar[2] = foo
ar[3] = bar
So, you have to write a function that will reconstruct the array. Someone pasted it to me but I can't find it.
Mike