PHP syntax for dereferencing function result

后端 未结 22 880
不知归路
不知归路 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条回答
  •  时光说笑
    2020-11-22 02:56

    There isn't a way to do that unfortunately, although it is in most other programming languages.

    If you really wanted to do a one liner, you could make a function called a() and do something like

    $test = a(func(), 1); // second parameter is the key.
    

    But other than that, func()[1] is not supported in PHP.

提交回复
热议问题