找到你要的答案

Q:How can I present this json data in this format?

Q:我怎么能在这种格式现在这个JSON数据?

I have json data in this format:

Array
(
    [type] => champion
    [version] => 5.15.1
    [data] => Array
        (
            [Thresh] => Array
                (
                    [id] => 412
                    [key] => Thresh
                    [name] => Thresh
                    [title] => the Chain Warden
                )

            [Aatrox] => Array
                (
                    [id] => 266
                    [key] => Aatrox
                    [name] => Aatrox
                    [title] => the Darkin Blade
                )

            [Tryndamere] => Array
                (
                    [id] => 23
                    [key] => Tryndamere
                    [name] => Tryndamere
                    [title] => the Barbarian King
                )

         )

)

How can I display this data in the following format in php with foreach loop ?

Name : Thresh
id : 412
key : Thresh
name : Thresh
title : the Chain Warden
------------------------------
Name : Aatrox
id : 266
key : Aatrox
name : Aatrox
title : the Darkin Blade
---------------------------------
Name : Tryndamere
id : 23
key : Tryndamere
name : Tryndamere
title : the Barbarian King
----------------------------------------------

我已经在这个格式JSON数据:

Array
(
    [type] => champion
    [version] => 5.15.1
    [data] => Array
        (
            [Thresh] => Array
                (
                    [id] => 412
                    [key] => Thresh
                    [name] => Thresh
                    [title] => the Chain Warden
                )

            [Aatrox] => Array
                (
                    [id] => 266
                    [key] => Aatrox
                    [name] => Aatrox
                    [title] => the Darkin Blade
                )

            [Tryndamere] => Array
                (
                    [id] => 23
                    [key] => Tryndamere
                    [name] => Tryndamere
                    [title] => the Barbarian King
                )

         )

)

我怎么能在下面的PHP Foreach循环格式显示这些数据?

Name : Thresh
id : 412
key : Thresh
name : Thresh
title : the Chain Warden
------------------------------
Name : Aatrox
id : 266
key : Aatrox
name : Aatrox
title : the Darkin Blade
---------------------------------
Name : Tryndamere
id : 23
key : Tryndamere
name : Tryndamere
title : the Barbarian King
----------------------------------------------
answer1: 回答1:

Iterate over $arr['data'] and just print results:

foreach ($arr['data'] as $name => $data) {
    echo 'Name:' . $name . PHP_EOL;
    echo 'id:' . $data['id'] . PHP_EOL;
    echo 'key:' . $data['key'] . PHP_EOL;
    echo 'name:' . $data['name'] . PHP_EOL;
    echo 'title:' . $data['title'] . PHP_EOL;
    echo '------------------------------' . PHP_EOL;
}

遍历ARR [数据]美元只是打印结果:

foreach ($arr['data'] as $name => $data) {
    echo 'Name:' . $name . PHP_EOL;
    echo 'id:' . $data['id'] . PHP_EOL;
    echo 'key:' . $data['key'] . PHP_EOL;
    echo 'name:' . $data['name'] . PHP_EOL;
    echo 'title:' . $data['title'] . PHP_EOL;
    echo '------------------------------' . PHP_EOL;
}
php  json