[nycphp-talk] highest key of an array
Ken Robinson
kenrbnsn at rbnsn.com
Mon Sep 19 17:21:37 EDT 2005
At 05:09 PM 9/19/2005, Odra Gola wrote:
>is there a quick way to return the numerically highest key of an
>array? (not the element)
>I wrote my own function to do it, but I'm affraid I'm reinventing the wheel
Use:
$a = array();
max(array_keys($a))
Example:
<?
$a = array();
for ($i=0;$i<rand(10,30);$i++)
$a[rand(30,100)] = rand(100,550);
echo 'Max key=' . max(array_keys($a)) . ' value=' .
$a[max(array_keys($a))];
echo '<br>Min key=' . min(array_keys($a)) . ' value=' .
$a[min(array_keys($a))];
echo '<br>Max value=' . max($a);
echo '<br>Min value=' . min($a);
?>
Ken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20050919/121e5b59/attachment.html>
More information about the talk
mailing list