filtering key-value pairs in a multidimensional array
am 01.10.2007 15:03:20 von Snaggy
I have a multidimensional array with a few entries I need to delete.
Key and values are not unique in different sub arrays.
As far as I know the filter function is not recursive and only deletes
values, not keys.
How can I do that?
thanks
Luca
Re: filtering key-value pairs in a multidimensional array
am 01.10.2007 15:08:57 von Erwin Moller
Snaggy wrote:
> I have a multidimensional array with a few entries I need to delete.
> Key and values are not unique in different sub arrays.
>
> As far as I know the filter function is not recursive and only deletes
> values, not keys.
>
> How can I do that?
>
> thanks
> Luca
>
Hi,
Then don't use filter, but use unset() on the elements you want to delete.
$arr = array(
"one" => array(1,"yes","no"),
"two" => 23,
"something" => array(array(1,2,3),55)
);
if you want to delete the 55:
unset ($arr["something"][1]);
if you want to delete the whole "something":
unset ($arr["something"]);
etc.
But without more information, this might be irrelevant. ;-)
Regards,
Erwin Moller