Re: get the greatest key of an array???

From: Date: Thu, 14 Mar 2002 15:04:03 +0000
Subject: Re: get the greatest key of an array???
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-88507@lists.php.net to get a copy of this message
On Thursday, March 14, 2002, at 09:47 AM, Alex Elderson wrote:
How can i get the greatest key of an array?? $array[1] = "..."; $array[5] = "..."; $array[0] = "..."; $array[10] = "..."; $array[7] = "..."; $greatest_key = ??? (this must be 10 in this example)
I think you mean the element with the greatest index? It's not guaranteed to be the "greatest" element in your array, depending on how you have set up your indexes (associative or numeric), but the end() function should do it: http://www.php.net/manual/en/function.end.php It sets the internal pointer to the very last element in the array. Python, incidentally, has a neat way of doing this: array[-1] (of course they're called lists, not arrays, in Python). Just a side note. Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com

« previous php.general (#88507) next »