Search for highest key/index in an array

大兔子大兔子 提交于 2019-11-28 04:15:42

This should work fine

$arr = array( 1 => "A", 10 => "B", 5 => "C" );
max(array_keys($arr));

You can get the maximum key this way:

<?php
$arr = array("a"=>"test", "b"=>"ztest");
$max = max(array_keys($arr));
?>
$keys = array_keys($arr);
$keys = rsort($keys);

print $keys[0];

should print "10"

Try max(): http://php.net/manual/en/function.max.php See the first comment on that page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!