PHP Coding Tips

Friday, August 17, 2012

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.

22 comments:

  1. New Bet | Online Casino USA | $25 No Deposit Bonus
    New Bet 카지노 casino USA bonus codes for 2021. Use our review tool and get the best bonuses from US 1xbet korean online casinos. Best bonuses. septcasino No deposit required.

    ReplyDelete