note 18650 added to language.types.array

From: Date: Wed, 30 Jan 2002 14:28:19 +0000
Subject: note 18650 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-26035@lists.php.net to get a copy of this message
I cannot find an easy, concise, efficient way to get at the last element of an array. I would love to be able to do something like: $array = array( 1 => 1, 2 => 2 ); echo $array[-1]; ...and get back "2". Unfortunately, what happens is that in $array[-1] the -1 is taken as a key value, and thus what I do get back is "null". The workaround I have, though cumbersome and horribly inefficient, is: print $array[ array_pop( array_keys( $array ) ) ]; ...which does, indeed, return "2". -- http://www.php.net/manual/en/language.types.array.php http://master.php.net/manage/user-notes.php?action=edit+18650 http://master.php.net/manage/user-notes.php?action=delete+18650 http://master.php.net/manage/user-notes.php?action=reject+18650

« previous php.notes (#26035) next »