從PHP 5.4,我可以調用一個元件的函數返回的數組的,像這樣:func()['el']
。在指定函數返回數組上調用數組鍵?
我運行PHP 5.6和測試以下(簡化)代碼:
作品
$decoded = json_decode($content, true)['foo'];
不起作用
($decoded = json_decode($content, true))['foo']; // syntax error ['
我不明白爲什麼我無法將json_decode($content, true)
指定爲$decoded
,並立即調用元素foo
。這工作正常php
爲什麼這是有趣的?
我PhpStorm 2017年2月1日,與應用PHP 5.6DOES NOT檢測該代碼作爲PHP只有7個可用!
無法複製:https://3v4l.org/b8Q0R。你可能不會運行你認爲你是PHP的版本。 – Calimero
我認爲你的json $內容有一些問題,你可以分享$ conent – shashi
'($ decode = json_decode($ content,true))['foo'];'5.6的語法不正確。看看https://3v4l.org/v3Tqt –