PHP syntax for dereferencing function result

后端 未结 22 897
不知归路
不知归路 2020-11-22 02:14

Background

In every other programming language I use on a regular basis, it is simple to operate on the return value of a function without declaring

22条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 02:44

    You can't chain expressions like that in PHP, so you'll have to save the result of array_test() in a variable.

    Try this:

    function array_test() {
      return array(0, 1, 2);
    }
    
    $array = array_test();
    echo $array[0];
    

提交回复
热议问题