Last Updated: February 25, 2016
· webfacer

Get last elements key in PHP

When you want to check if you at the end of an array for whatever reason you can use this short phpline:

    $arr = array(1, 'test', 'i am the last element');
    $lastElementKey = array_pop(array_keys($arr));

it throws you the last key of the Array (in our case it will throw the key 2 out).