Originally posted by ppowell
Turns out the problem was more simplistic than that.. unset($array[$key]) is the normal way to go, except that in $_SESSION variables it's a whole new ballgame if register_globals is turne d off, using PHP 4.1.2+ and if you are trying to destroy session variables within a class method.
Yah, a lot of conditions there 😉
Thanx, the function looks cool and might come in handy with a slight modification of:
if (isset($array[$key])) // DO THE FUNCTION
Phil [/B]
The function removes a key/value pair and renumbers the array. Sweet because it's recursive. Consider (though you probably have already):
% cat shift
<?php
function array_trim ( $array, $index ) {
if ( is_array ( $array ) ) {
unset ( $array[$index] );
array_unshift ( $array, array_shift ( $array ) );
return $array;
}
else {
return false;
}
}
$fooray=array("foo","bar","baz","qux","garply");
$foobar=array_trim($fooray, 3);
print_r($foobar);
?>
% php shift
Array
(
[0] => foo
[1] => bar
[2] => baz
[3] => garply
)
As if 'twere never even there!
Have a good day....