Page 1 of 1

php max key from array

Posted: Wed May 04, 2016 6:03 pm
by mister_v
Hi,

how do I get the biggest key out of an array?

Code: Select all

$arr = array( 1 => 'c', 10 => 'z', 4 => 'A' );
I can do it with a foreach loop,
but I'm hoping there is a easier way.

thanks.

Re: php max key from array

Posted: Fri Aug 05, 2016 12:57 pm
by chris
You can get the highest key-nr with this :

Code: Select all

$max = max(array_keys($arr));