Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道这种事情是否会在 PHP 中成为可能(以及它是否已经存在并且我只是错过了一些东西......)
<?php function test() { return array( 'id'=>10, 'name'=>'John' ); } echo 'Your name is: '.test()['name']; ?>
我真的很希望能够直接使用返回的数组,而不是先将它们分配给 var... 可能吗?
简单的回答:不这么认为
PHP 词法分析器无法识别此类语句,因此更改将需要在 PHP 的核心组件中进行一些重大更改。尽管我必须承认,我看不出词法分析器以这种方式编写的任何原因。
不,你不能这样做,但是使用 php5 和 OOP,你有一些选择......