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

Web Developer, Business Analytics, Data Engineer specialising in PHP and Tableau

Based in Melbourne, Australia

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

Leave a comment

Name Notify me of replies by email.