Remove a dimension of an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
flycast
Forum Commoner
Posts: 37
Joined: Wed Jun 01, 2005 7:33 pm

Remove a dimension of an array

Post 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]
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Remove a dimension of an array

Post by requinix »

If the dimensions are fixed then you can use a bunch of unsets. Otherwise you'll need a loop somewhere.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Remove a dimension of an array

Post by Mark Baker »

array_walk(), but it's still basically implementing a loop
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Remove a dimension of an array

Post by jackpf »

Post Reply