解码json并做一个foreach来获取每个数组的值?

时间:2014-11-08 09:10:50

标签: php arrays json

我是PHP新手,我有以下JSON,我想打印每个数组的值。

JSON

[
  ["38", "App Name1", "Long description.", "http:\/\/url.com", "5"],
  ["12", "Name 2", "Long description goes here...", "http:\/\/test.com", "100"]
]

我希望将其打印为:

App Name 1
Long description
http://url.com
5

Name 2
Long description goes here...
http://test.com
100

我无法让它发挥作用。任何人都可以帮我这个吗?

1 个答案:

答案 0 :(得分:0)

试试这个

$a='[
    ["38", "App Name1", "Long description.", "http:\/\/url.com", "5"
    ],
    ["12", "Name 2", "Long description goes here...", "http:\/\/test.com", "100"
        ]    
    ]';
$ja=json_decode($a);
if(count($ja)>0)foreach($ja as $jv){
    echo $jv[1]."<br/>";
    echo $jv[2]."<br/>";
    echo $jv[3]."<br/>";
    echo $jv[4]."<br/><br/>";
}

output:

App Name1
Long description.
http://url.com
5

Name 2
Long description goes here...
http://test.com
100