Define array index after function call

前端 未结 2 973
独厮守ぢ
独厮守ぢ 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 19:18

    // PHP 5.4
    $item = getMyArray()[0];
    
    // Older than 5.4: (not recommended)
    list($a)   = getMyArray();  // getMyArray()[0]
    list(, $b) = getMyArray();  // getMyArray()[1]
    

提交回复
热议问题