Re: Array function to delete

From: Date: Thu, 25 Apr 2002 20:00:45 +0000
Subject: Re: Array function to delete
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-94645@lists.php.net to get a copy of this message
Apparently in 4.1.X this is true... I'd been running 4.0.6 for a long time (until 4.1.2 was released), and must have coded it in the earlier version. I stand corrected! :-) A simple test to see if your version supports this: <?php $array = array(); $array[0] = "zero"; $array[1] = "one"; $array[2] = "two"; $array[3] = "three"; unset($array[1]); foreach ($array as $key=>$value) { echo $key." = ".$value."<BR>"; } ?> If you're running an older version, it should output: 0 = zero 1 = 2 = two 3 = three Versions 4.1.X+ should completely remove key 1. Cheers, # Nathan ----- Original Message ----- From: "Lars Torben Wilson" <torben@php.net> To: "Nathan" <etherwolf@sopris.net> Cc: "Liam Gibbs" <liamgibbs@yahoo.com>; "PHP" <php-general@lists.php.net> Sent: Friday, April 26, 2002 1:46 PM Subject: Re: [PHP] Array function to delete On Thu, 2002-04-25 at 12:34, Nathan wrote: > No. :-) > > What I've had to do is add a dummy value, unset($array[4]) and then array_pop the dummy > value off > the array to get it out of there completely. The reason: unset will only remove > $array[4]'s value, > not the key. > > There are plenty of other ways I'm sure, but simply unsetting has really messed me up on > occasion. > I'll unset a value and then implode my array (say a list of numbers), and end up with a > string like > so: > > 1,233,642,,234,5632, > > Where I've unset the 4th and last keys. Which of course really messes up an explode. > > # Nathan You need to upgrade. :) The above hasn't been true for a while...at least since 4.1.2 and perhaps earlier.

« previous php.general (#94645) next »