puzzled by format of PHP multi dimensional array

Sorry if this is a duplication of anyone elses question but in my eyes it doesn't appear to match any other PHP multi dimensional array questions on here. And I've read them all. :-(

I'm trying to access values of this array (which I have no control over). But it's format is puzzling me and as yet I can't get at the values how I thought I should be able to.

This my JSON array example.

 {"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}]}

I naively thought that assigning this Json array to $arr Then decoding like so.

$arr = json_decode($str,true);

once done i could reference the array values like so...

$UrlTo = $arr['Result']['Links']['UrlTo'];

But I'm clearly not understanding this right. I've spent a lot of time googling, reading and still don't get it. I think it will be obvious to someone more experienced than I? Can someone help me understand the naivity of my approach.


It's:

$arr['Result'][0]['Links'][0]['UrlTo'];

$arr['Result'] is an array, as is $arr['Result'][0]['Links']

To get the other result, do:

$arr['Result'][1]['Links'][0]['UrlTo'];
链接地址: http://www.djcxy.com/p/57672.html

上一篇: 从数组中移除一个嵌套数组并在php中分配一个新变量

下一篇: 对PHP多维数组格式感到困惑