2013-04-03 107 views
0

我有這樣的數組。該陣列是動態創建如何迭代多維數組?

Array 
(
    [Data NotUploading] => Array 
    (
     [items] => Array 
      (
       [0] => Array 
        (
         [date] => 2013-04-02 
         [issue_id] => 1 
         [phone_service_device] => A 
         [phone_service_model] => 
         [phone_service_os] => 
         [phone_service_version] => 
         [issue_name] => Data NotUploading 
        ) 

       [1] => Array 
        (
         [date] => 2013-04-02 
         [issue_id] => 1 
         [phone_service_device] => I 
         [phone_service_model] => 
         [phone_service_os] => 
         [phone_service_version] => 
         [issue_name] => Data NotUploading 
        ) 



      ) 

    ) 

[Battery Problem] => Array 
    (
     [items] => Array 
      (
       [0] => Array 
        (
         [date] => 2013-04-03 
         [issue_id] => 3 
         [phone_service_device] => I 
         [phone_service_model] => 
         [phone_service_os] => 
         [phone_service_version] => 
         [issue_name] => Battery Problem 
        ) 

      ) 

    ) 
) 

我需要做的是使用2 foreach或1的foreach & 1 for循環,這樣我可以得到最新的每個值我不喜歡這個

foreach($gResultbyName as $key1 => $rec){ 
     for($j = 0;$j<count($rec);$j++){ 
      echo $rec['items'][$j]['date']; 
     } 
    } 

但其唯一檢索2013-04-02 & 2013-04-03即0索引數據日期NotUploading & 0電池問題索引日期。基本上我需要比較每個值和其他的東西,但我不能得到每個日期值。

請原諒我的無知,但我嘗試了很多:(

回答

3

試試這個:

foreach ($data as $d) 
{ 
    foreach($d['items'] as $item) 
    { 
     echo $item['date']; 
    } 
} 
2

您的循環迴路count($rec)倍,而應該count($rec['items'])

2

這應該加載日期進入一個按照issue_name排序的數組,你可以通過它們進行進一步處理

$dates= array(); 
foreach ($gResultbyName AS $events){ 
    foreach ($events['items'] AS $item){ 
     $dates[$item['issue_name']][] = $item['date']; 
    } 
} 
var_dump($dates);