php max key from array

All your question about php
Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

php max key from array

Post 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.
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: php max key from array

Post by chris »

You can get the highest key-nr with this :

Code: Select all

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