91az2w
Last Updated: February 25, 2016
·
2.798K
· webfacer
1ac40ea49b742e19deae3940d1228472

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:

<?php
    $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).

Say Thanks
Respond