RE: [PHP-WIN] array_pop

From: Date: Fri, 06 Oct 2000 07:50:40 +0000
Subject: RE: [PHP-WIN] array_pop
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-2984@lists.php.net to get a copy of this message
Ok, I see what you're saying. Just unset the last item of the array, which i get from $max=count($array). Nice. In order for my code to work with this in an easier way, one should first set the pointer to the last item of the array with end($array). So a code like below works just fine in emulating array_pop() with PHP3. <? $arr["one"] = "ha"; $arr[1] = "hmm"; $arr["two"] = "he"; $arr["three"] = "ho"; end($arr); list($key) = each($arr); unset($arr[$key]); end($arr); list($key, $val) = each($arr); echo "<li>$key : $val\n"; ?> -----Original Message----- From: Jens Wabnitz [mailto:wabnitz@gmx.de] Sent: Thursday, October 05, 2000 7:14 PM To: Nicolae Doca Cc: php-windows@lists.php.net Subject: AW: [PHP-WIN] array_pop Hi Nicolae, not tested, but should work. <? $arr["one"] = "ha"; $arr[1] = "hmm"; $arr["two"] = "he"; $arr["three"] = "ho"; $max = count($arr); $cnt =1; while (list($key, $val) = each($arr)) { print "$cnt: $key => $val <BR>"; if ($cnt == $max) { print $val; unset($arr[$key]); } $cnt++; } ?> Bye Jens -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net For additional commands, e-mail: php-windows-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.windows (#2984) next »