2012-08-14 80 views
0

我想從這個多維數組中包含的每個數組中拉出'消息'數據,但無法弄清楚如何獲得足夠深的數組來拉動它。我正在使用的頁面以這種方式返回數據,因此我無法編輯它以不同的方式返回。從多維PHP數組中提取特定數據

Array 
(
[0] => stdClass Object 
    (
     [revision_cache] => stdClass Object 
      (
       [revision] => 14 
       [email] => [email protected] 
       [changed_dirs] => Array 
        (
        ) 

       [account_id] => 133673 
       [message] => Deleted unneeded help desk files. 
       [hash_id] => 
       [author] => asdfasfd 
       [too_large] => 
       [user_id] => 308011 
       [repository_id] => 401677 
       [changed_files] => Array 
        (
         [0] => Array 
          (
           [0] => hdeskdelete.php 
           [1] => delete 
          ) 

         [1] => Array 
          (
           [0] => hdeskrespond.php 
           [1] => delete 
          ) 

         [2] => Array 
          (
           [0] => hdesktickets.php 
           [1] => delete 
          ) 

        ) 

       [time] => 2012/08/13 17:01:58 -0500 
       [changed_properties] => 
      ) 

    ) 

[1] => stdClass Object 
    (
     [revision_cache] => stdClass Object 
      (
       [revision] => 13 
       [email] => [email protected] 
       [changed_dirs] => Array 
        (
        ) 

       [account_id] => 133673 
       [message] => Major updates and restyling of Help Desk system. 
       [hash_id] => 
       [author] => asdfasdfasdf 
       [too_large] => 
       [user_id] => 308011 
       [repository_id] => 401677 
       [changed_files] => Array 
        (
         [0] => Array 
          (
           [0] => members/hdeskdelete.php 
           [1] => delete 
          ) 

         [1] => Array 
          (
           [0] => Array 
            (
             [0] => helpdesk.php 
             [1] => members/helpdesk.php 
             [2] => 3 
            ) 

           [1] => copy 
          ) 

         [2] => Array 
          (
           [0] => members/hdeskrespond.php 
           [1] => delete 
          ) 

         [3] => Array 
          (
           [0] => members/hdesktickets.php 
           [1] => delete 
          ) 

         [4] => Array 
          (
           [0] => Array 
            (
             [0] => hdeskdelete.php 
             [1] => members/hdeskdelete.php 
             [2] => 3 
            ) 

           [1] => copy 
          ) 

         [5] => Array 
          (
           [0] => members/helpdesk.php 
           [1] => delete 
          ) 

         [6] => Array 
          (
           [0] => Array 
            (
             [0] => hdeskrespond.php 
             [1] => members/hdeskrespond.php 
             [2] => 3 
            ) 

           [1] => copy 
          ) 

         [7] => Array 
          (
           [0] => Array 
            (
             [0] => hdesktickets.php 
             [1] => members/hdesktickets.php 
             [2] => 3 
            ) 

           [1] => copy 
          ) 

        ) 

       [time] => 2012/08/13 17:01:20 -0500 
       [changed_properties] => 
      ) 

    ) 

[2] => stdClass Object 
... 

所以基本上,這個數組塊塊會持續一段時間。每次「消息」是關鍵時,我只需要拉取值。有任何想法嗎?

回答

1

要遍歷數組中的所有元素,同時檢查,如果該消息是存在的,這樣的事情:

foreach($inputArray as $element) 
{ 
    if(! empty($element->revision_cache->message) 
    { 
     //do something with it 
    } 
} 
+0

完美。它完全符合我所需要的。謝謝! – xxdrivenxx 2012-08-14 06:46:46

0

這應做到:

$message = $arrayname[0]["revision_cache"]["message"]; 
+0

子元素是*不是*數組,它們是對象 – orourkek 2012-08-14 06:45:03

+0

糟糕...確實,我的壞! – Borniet 2012-08-14 06:46:05

0

嘗試

foreach($array as $item){ 
    echo $item->revision_cache->message."<br>"; 
}