Deleting values from 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Deleting values from an array

Post by aceconcepts »

Hi,

I have the following array: Array ( [0] => Array ( [1] => Array ( [0] => 1 [1] => 4 ) ) )

What I am trying to do is delete a specific value from this array e.g. sya I need to delete the value 4 from the third nested array, how could I do this without effecting the rest of the arrays?

Thanks.
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: Deleting values from an array

Post by EverLearning »

You unset by providing the path to the array element that contains value 4(you access array values by keys)

Code: Select all

unset($array[0][1][1]);
Post Reply