Page 1 of 1

Remove a dimension of an array

Posted: Sun Sep 13, 2009 7:27 pm
by flycast
Is it possible without looping through the array to remove a every element with a certain key in one of the dimensions? Say you have an array 3x5 in size:
$array[0-2, 0-4]
and you have values in all those positions. Does anybody know how to remove all the array values that have a "3" key in the second position without looping through them? In other words...unset the following:
$array[0,3]
$array[1,3]
$array[2,3]

Re: Remove a dimension of an array

Posted: Sun Sep 13, 2009 7:47 pm
by requinix
If the dimensions are fixed then you can use a bunch of unsets. Otherwise you'll need a loop somewhere.

Re: Remove a dimension of an array

Posted: Mon Sep 14, 2009 4:37 am
by Mark Baker
array_walk(), but it's still basically implementing a loop

Re: Remove a dimension of an array

Posted: Mon Sep 14, 2009 7:37 am
by jackpf