需要在php中打印数组中的数据

时间:2014-08-04 13:44:40

标签: php arrays

我每天都从我的服务器动态获取这个数组:

这是数组:

Array ( 
    [status] => success 
    [summary] => Array ( 
        [views] => 481 
        [clicks] => 251 
        [downloads] => 222 
    ) 
    [detailed] => Array ( 
        [2014-08-02] => Array ( 
            [views] => 59 
            [clicks] => 34 
            [downloads] => 27
        )
        [2014-08-03] => Array ( 
            [views] => 252 
            [clicks] => 135 
            [downloads] => 120 
        ) 
        [2014-08-04] => Array ( 
            [views] => 170 
            [clicks] => 82 
            [downloads] => 75 
        ) 
    ) 
    [countries] => Array ( 
        [PH] => 11 
    ) 
) 

我想用他的数据只打印[detailed]数组,但我不知道该怎么做。

我用过这个:

foreach($responseData[detailed] as $child1) {
    foreach($child1 as $child) {
       echo $child ." ";
    }
    echo "\n";
}

但它打印的所有数据都没有日期:

59 34 27 
252 135 120 
170 82 75 

我希望它是这样的:

2014-08-02 - 59 34 27 
2014-08-03 - 252 135 120 
2014-08-04 - 170 82 75 

请记住,我每天都会收到不同日期的漂网网络数据。

感谢

2 个答案:

答案 0 :(得分:2)

foreach($responseData['detailed'] as $key => $child1) {
    echo $key, ' - ';
    foreach($child1 as $child) {
       echo $child ." ";
    }
    echo "\n";
}

答案 1 :(得分:1)

而不是在循环中使用循环,您也可以使用implode

   foreach($responseData['detailed'] as $key => $child1) {
    echo $key, ' - ';
    echo implode(" ", $child1);
    echo "\n";
}