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
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to