很抱歉,如果这是任何人的问题重复,但在我看来,它似乎与此处的任何其他PHP多维数组问题不匹配。而且我已经读过它们了。 : - (
我正在尝试访问此数组的值(我无法控制)。但是它的格式令我感到困惑,但是我无法理解我应该能够达到的价值。
这是我的JSON数组示例。
{"Result":[{"Links":[{"UrlTo":"blahblahA/","Visited":1380104406,"FirstSeen":1375979058,"PrevVisited":1379817016,"Anchor":"text links","Type":"Text","Flag":[],"TextPre":"","TextPost":""}],"Index":0,"Rating":18.44400799929153,"UrlFrom":"blahblahB","IpFrom":"209.18.x.11","Title":"home page","LinksInternal":16,"LinksExternal":5,"Size":13107},{"Links":[{"UrlTo":"blahblahABC","Visited":1380574695,"FirstSeen":1375979100,"PrevVisited":1379224472,"Anchor":"text links","Type":"Text","Flag":[],"TextPre":"","TextPost":""}],"Index":1,"Rating":11.02675617091105,"UrlFrom":"blahblahXYZ","IpFrom":"209.18.x.11","Title":"Random title","LinksInternal":16,"LinksExternal":5,"Size":13107}]}
我天真地认为将这个Json数组分配给$ arr 然后像这样解码。
$arr = json_decode($str,true);
一旦完成,我可以像这样引用数组值......
$UrlTo = $arr['Result']['Links']['UrlTo'];
但我显然不理解这一点。 我花了很多时间谷歌搜索,阅读,但仍然没有得到它。 我认为对于比我更有经验的人来说,这是显而易见的吗? 有人可以帮助我理解我的方法的天真。
答案 0 :(得分:5)
这是:
$arr['Result'][0]['Links'][0]['UrlTo'];
$arr['Result']
是一个数组,$arr['Result'][0]['Links']
要获得其他结果,请执行以下操作:
$arr['Result'][1]['Links'][0]['UrlTo'];