Re: delete an element from an array

From: Date: Mon, 05 Mar 2001 16:36:35 +0000
Subject: Re: delete an element from an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-42630@lists.php.net to get a copy of this message
kaab kaoutar [kaab_k@hotmail.com] wrote: > Thanks! but i know this function! > i can't do that cause my varibale is multidimenssional, and i don't want to > update all that ! for one element ! > we can't decrement the length of the array ?! no way ? Here's an example of a multidimensional array - I "unset" one of the values in the middle - I don't know why this won't work for you: <? $arr1 = array("a" => array('1' => "a111", '2' => "a222", '3' => "a333"), "b" => array('1' => "b111", '2' => "b222", '3' => "b333"), "c" => array('1' => "c111", '2' => "c222", '3' => "c333")); foreach ($arr1 as $key1 => $value1) { echo "<br>"; echo "key=[$key1], value=[$value1]<br>"; foreach ($value1 as $key2 => $value2) { echo " key2=[$key2], value2=[$value2]<br>"; } } unset($arr1["b"]["2"]); echo "<br><br>Unset b2 now<br><br>"; foreach ($arr1 as $key1 => $value1) { echo "<br>"; echo "key=[$key1], value=[$value1]<br>"; foreach ($value1 as $key2 => $value2) { echo " key2=[$key2], value2=[$value2]<br>"; } } ?> Here's the output displayed on the browser: ------------------------------------------- key=[a], value=[Array] key2=[1], value2=[a111] key2=[2], value2=[a222] key2=[3], value2=[a333] key=[b], value=[Array] key2=[1], value2=[b111] key2=[2], value2=[b222] key2=[3], value2=[b333] key=[c], value=[Array] key2=[1], value2=[c111] key2=[2], value2=[c222] key2=[3], value2=[c333] Unset b2 now key=[a], value=[Array] key2=[1], value2=[a111] key2=[2], value2=[a222] key2=[3], value2=[a333] key=[b], value=[Array] key2=[1], value2=[b111] key2=[3], value2=[b333] key=[c], value=[Array] key2=[1], value2=[c111] key2=[2], value2=[c222] key2=[3], value2=[c333] > > > > >From: Hardy Merrill <merrill@missioncriticallinux.com> > >To: kaab kaoutar <kaab_k@hotmail.com> > >CC: php-general@lists.php.net > >Subject: Re: [PHP] delete an element from an array > >Date: Mon, 5 Mar 2001 10:57:49 -0500 > > > >Have a look at > > > > http://www.php.net/manual/en/function.unset.php > > > >"unset" may do what you want. > > > >HTH. > > > >-- > >Hardy Merrill > >Mission Critical Linux, Inc. > >http://www.missioncriticallinux.com > > > >kaab kaoutar [kaab_k@hotmail.com] wrote: > > > > > > Hi! > > > FIRST OF ALL THANKS ! > > > well do u mean that the only way to remove an elemnt from an array is to > > > copy it into another array? it does not suit me cause the array is a > >session > > > variable and i need to update it ! > > > > > > Thanks > > > > >_________________________________________________________________________ > > > Get Your Private, Free E-mail from MSN Hotmail at > >http://www.hotmail.com. > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-general-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > >-- > >PHP General Mailing List (http://www.php.net/) > >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > >For additional commands, e-mail: php-general-help@lists.php.net > >To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > _________________________________________________________________________ > Get Your Private, Free E-mail from MSN Hotmail at > http://www.hotmail.com. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- Hardy Merrill Mission Critical Linux, Inc. http://www.missioncriticallinux.com

« previous php.general (#42630) next »