简体   繁体   English

从PHP中的数组返回值

[英]Return value from array in PHP

I'm trying to return the value [name] from the following array (last.fm) 我正在尝试从以下数组(last.fm)返回值[name]

Array
(
[totalResults] => 9771
[startIndex] => 0
[itemsPerPage] => 1
[results] => Array
    (
        [0] => Array
            (
                [name] => Beyoncé
                [mbid] => 183105b5-3e68-4748-9086-2c1c11bf7a3d
                [url] => http://www.last.fm/music/Beyonc%C3%A9
                [streamable] => 1
                [image] => Array
                    (
                        [small] => 
                        [large] => http://userserve-ak.last.fm/serve/34/95313353.png
                    )

            )

    )

)

I tried 我试过了

echo $results['0'][0];

Where $results is the array variable, but not worked. $ results是数组变量,但不起作用。 I have no clue. 我没有任何线索。 Can you help me to retune the value from [name] (in this case Beyonce) ? 您能帮我从[name](在本例中为Beyonce)调整值吗?

Thanks in advance 提前致谢

You need to access each nested result by it's key. 您需要通过键访问每个嵌套结果。 In this case "results" > 0 (numeric index) > "name": 在这种情况下,“结果”> 0(数字索引)>“名称”:

echo $results['results'][0]['name'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM