Get the largest key in an array with PHP : How to

<?php
    
    /*
     * To get the largest key in an array
     */ 
    $array = array( 0 => 'first', 1=> 'second', /* ... */ 99 => 'nth' );
    $max_key = max( array_keys( $array ) ); // 99
?>

Refer gist for comments https://gist.github.com/justinkelly/1226364

Justin Kelly

Justin Kelly

Data Engineeer, Business Analytics, Web Developer, Library Technology specialising in PHP and Tableau

Based in Melbourne, Australia

Feel free to contact me justin@kelly.org.au or _justin_kelly