PHP:我可以引用由函数返回一个数组的单个成员? [英] PHP: Can I reference a single member of an array that is returned by a function?
本文介绍了PHP:我可以引用由函数返回一个数组的单个成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何想法如何,如果在PHP以下是可能为单行:
any idea how if the following is possible in PHP as a single line ?:
<?php
$firstElement = functionThatReturnsAnArray()[0];
...这似乎并不拿走。我需要做的这是一个2步进:
... It doesn't seem to 'take'. I need to do this as a 2-stepper:
<?php
$allElements = functionThatReturnsAnArray();
$firstElement = $allElements[0];
...只是好奇 - 其他语言我一起玩允许这样的事情,我很懒惰enoug在PHP错过这个......任何见解AP preciated ...
... just curious - other languages I play with allow things like this, and I'm lazy enoug to miss this in PHP ... any insight appreciated ...
推荐答案
尝试:
<?php
$firstElement = reset(functionThatReturnsAnArray());
如果你只是在寻找数组的第一个元素。
If you're just looking for the first element of the array.
这篇关于PHP:我可以引用由函数返回一个数组的单个成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文