Get last element of an array in PHP
To get last element of an array just use end() function. First idea can by get a index at count()-1 but remember that php arrays are associative arrays, so you can grab last element just by number.
$lastElement = end($array);
As simple as you see. It works even if your indexes are strings like 'name','surname' etc.
Comments
Post a Comment