Define array index after function call

前端 未结 2 961
独厮守ぢ
独厮守ぢ 2020-12-06 18:15

In other languages such as C# and JavaScript, I am able to access the index of an array with a function call such as

getMyArray()[0] 

This

相关标签:
2条回答
  • 2020-12-06 18:53

    You need to be running PHP 5.4 in order to use array de-referencing.

    0 讨论(0)
  • 2020-12-06 19:18
    // PHP 5.4
    $item = getMyArray()[0];
    
    // Older than 5.4: (not recommended)
    list($a)   = getMyArray();  // getMyArray()[0]
    list(, $b) = getMyArray();  // getMyArray()[1]
    
    0 讨论(0)
提交回复
热议问题