在PHP中,对任何给定函数、它们返回的变量或对函数本身的调用都是调用


In PHP are recalls to any given function the variable they return or a call to the function itself

例如:

<?php
    $text="/p hello";
    $a= explode("/",$text);
    $a=$a[1];
    echo $a;
?>
然而,

作品:

<?php
    $text="/p hello";
    $a= explode("/",$text)[1];
    echo $a;
?>

导致语法错误。在python中,你可以将调用返回列表/数组的函数视为列表/数组。对于php也是一样的吗?

在PHP版本>= 5.4.0中,它不会导致错误,但会返回p_hello。你可以在这里查看,修改版本号:

http://sandbox.onlinephpfunctions.com/code/db319c296ea4eb9500b9fa16bccd8f927c733d14

称为函数数组解引用:

https://wiki.php.net/rfc/functionarraydereferencing