note 18650 rejected from language.types.array by zak

From: Date: Wed, 30 Jan 2002 14:45:57 +0000
Subject: note 18650 rejected from language.types.array by zak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-26036@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".

« previous php.notes (#26036) next »