这只是一个好奇的问题…我想知道在这个方法中访问函数返回的数组是否有效。在这个例子中,我使用的是pathinfo()生成的数组。
pathinfo($file)['dirname'];
或者,是否需要先将pathinfo()设置为一个变量,然后再访问它?(经典方法):
$info = pathinfo($file);
$info['dirname'];
我知道经典方法是有效的,但我只是好奇如果第一个方法也是有效的。我已经用最新版本的WAMP测试过了,但是Dreamweaver CS5称它为语法错误。
PHP 5.4+支持pathinfo($file)['dirname'];
称为数组解引用
裁判:http://www.schlueters.de/blog/archives/138-Features-in-PHP-trunk-Array-dereferencing.html
裁判:http://php.net/manual/en/language.types.array.php
且小于5.4
$info = pathinfo($file);
$info['dirname'];
从PHP 5.4开始,可以这样做:
http://php.net/manual/en/language.types.array.php的例子- 88