The problem with unset() is this.
$text[0] = 0;
$text[1] = 1;
$text[2] = 2;
$text[3] = 3
$text[4] = 4;
// -note- will work
foreach ($text as $val)
echo "text[$c] == $val \n";
// -note- will work
for ($c = 0; $c < count($text); $c++)
echo "text[$c] == $text[$c] \n";
unset($text[2]);
// -note- will work
foreach ($text as $val)
echo "text[$c] == $val \n";
// -note- will NOT work
for ($c = 0; $c < count($text); $c++)
echo "text[$c] == $text[$c] \n";
// -----------------------
function del_elem($old_arr, $index)
{
foreach ($text as $key => $val)
{
if ($key != $index)
$new_arr[] = $old_arr[$key];
}
return $new_arr;
}
$text[0] = 0;
$text[1] = 1;
$text[2] = 2;
$text[3] = 3
$text[4] = 4;
// -note- will work
foreach ($text as $val)
echo "text[$c] == $val \n";
// -note- will work
for ($c = 0; $c < count($text); $c++)
echo "text[$c] == $text[$c] \n";
$text = del_elem($text, 2);
// -note- will work
foreach ($text as $val)
echo "text[$c] == $val \n";
// -note- will work
for ($c = 0; $c < count($text); $c++)
echo "text[$c] == $text[$c] \n";
// ------------------
the last example will shift all the elements in the array. ie.
$text[0] = 0;
$text[1] = 1;
$text[2] = 2;
$text[3] = 3
$text[4] = 4;
then becomes
$text[0] = 0;
$text[1] = 1;
$text[2] = 3;
$text[3] = 4
The last example will NOT work for index's like this.
$text["chris"] = 0;
$text["lee"] = 1;
$text["was"] = 2;
$text["here"] = 3
$text["today"] = 4;
it will make them this....
$text[0] = 0;
$text[1] = 1;
$text[2] = 3;
$text[3] = 4
Thats not what you want.
Hope this helps.
Chris Lee