How to return an array and get the first element of it in one line in PHP?

后端 未结 4 1716
轮回少年
轮回少年 2021-01-22 16:58

this question is just for fun and maybe learning a PHP shorthand trick (if exists) Let\'s assume that I have this code:

$item = $this->get_item($id);
$item =          


        
4条回答
  •  天涯浪人
    2021-01-22 17:29

    You can use reset($array) to reset the internal array position and return the value of the first element.

提交回复
热议问题