2013-05-31 66 views
0

我有這樣拼合嵌套數組到某些關鍵

Array 
(
    [0] => Array 
     (
      [actionResult] => Array 
       (
        [show_page] => Array 
         (
          [15] => Array 
           (
            [section_page_id] => 15 
            [metadata_id] => 62 
            [section_id] => 7 
            [display_order] => 0 
            [current_layout] => 15 
            [behaviors] => a:1:{i:0;a:1:{i:0;a:0:{}}} 
            [options] => a:1:{s:13:"defaultLayout";i:63;} 
            [section_title] => Ask Study 
           ) 

          [16] => Array 
           (
            [section_page_id] => 16 
            [metadata_id] => 66 
            [section_id] => 7 
            [display_order] => 1 
            [current_layout] => 16 
            [behaviors] => a:0:{} 
            [options] => a:1:{s:13:"defaultLayout";i:67;} 
            [section_title] => Ask Study 
           ) 

          [17] => Array 
           (
            [section_page_id] => 17 
            [metadata_id] => 69 
            [section_id] => 7 
            [display_order] => 2 
            [current_layout] => 17 
            [behaviors] => a:0:{} 
            [options] => a:1:{s:13:"defaultLayout";i:70;} 
            [section_title] => Ask Study 
           ) 

          [18] => Array 
           (
            [section_page_id] => 18 
            [metadata_id] => 72 
            [section_id] => 7 
            [display_order] => 3 
            [current_layout] => 18 
            [behaviors] => a:0:{} 
            [options] => a:1:{s:13:"defaultLayout";i:73;} 
            [section_title] => Ask Study 
           ) 

         ) 

       ) 

     ) 

    [1] => Array 
     (
      [actionResult] => Array 
       (
        [view_page] => 18 
       ) 

     ) 

) 

的數據結構我需要的就是擊敗這對一個數組結構,以一個點的能力,它停在「的ActionResult」,所有的actionResult將成爲一個數組而不是像這樣嵌套...

我該如何去做這個在PHP中?

+0

你有什麼試過? ,WHYT。問題是什麼?這應該是相當容易的PHP。 – OptimusCrime

回答

0

如果我明白你要正確地什麼這應該工作:

$arr2=array(); 

foreach($arr as $tmp){ 
    foreach($tmp as $actionRequest){ 
    foreach($actionRequest as $key=>$val){ 
     $arr2[$key]=$val; 
    } 
    } 
} 

其中$ ARR是你已經有了和$ ARR2將包括2個值,Show_Page和view_page

+0

這不會工作,因爲我可能有上面的列表,並有另一個可能沒有像你看到的額外的內部陣列... – Benjamin

0

最佳數組解決方案是:

$new_arr = array_map(function ($a) { 
    return $a['actionResult']; 
}, $old_arr); 
+0

謝謝我會嘗試 – Benjamin

+0

沒有工作... – Benjamin

+0

是你的PHP版本* * 5.2 **? – mpyw