2014-02-24 76 views
0

我有一個類似語法的數組...我想合併此array中的所有arrays以具有單個array。 9後index應該是10 ...合併數組中的匿名數組以獲得平坦的一個數組

Array 
(
    [0] => Array 
     (
      [0] => stdClass Object 
       (
        [ref_id] => 249 
        [address] => P.O. Box 496, 5760 Ultrices. Rd. 
        [email] => [email protected] 
        [phone] => 0926 326 7612 
       ) 

      [1] => stdClass Object 
       (
        [ref_id] => 2827 
        [address] => 885 Duis Avenue 
        [email] => [email protected] 
        [phone] => 070 6855 4104 
       ) 

      [2] => stdClass Object 
       (
        [ref_id] => 3228 
        [address] => 861-6767 Mauris St. 
        [email] => [email protected] 
        [phone] => 055 2515 3214 
       ) 

      [3] => stdClass Object 
       (
        [ref_id] => 3327 
        [address] => Ap #815-4752 Tellus. Rd. 
        [email] => [email protected] 
        [phone] => 07624 189445 
       ) 

      [4] => stdClass Object 
       (
        [ref_id] => 3567 
        [address] => 1115 Urna Ave 
        [email] => [email protected] 
        [phone] => (011221) 81949 
       ) 

      [5] => stdClass Object 
       (
        [ref_id] => 4259 
        [address] => P.O. Box 177, 8135 A Rd. 
        [email] => [email protected] 
        [phone] => (014143) 06426 
       ) 

      [6] => stdClass Object 
       (
        [ref_id] => 4547 
        [address] => 759-2274 Purus Rd. 
        [email] => [email protected] 
        [phone] => 076 4327 8034 
       ) 

      [7] => stdClass Object 
       (
        [ref_id] => 4607 
        [address] => 2858 Enim St. 
        [email] => [email protected] 
        [phone] => (01567) 19032 
       ) 

      [8] => stdClass Object 
       (
        [ref_id] => 4660 
        [address] => P.O. Box 131, 3992 Ipsum St. 
        [email] => [email protected] 
        [phone] => 076 4310 5712 
       ) 

      [9] => stdClass Object 
       (
        [ref_id] => 4677 
        [address] => 2813 A, Av. 
        [email] => [email protected] 
        [phone] => 0845 46 49 
       ) 

     ) 

    [1] => Array 
     (
      [0] => stdClass Object 
       (
        [ref_id] => 4783 
        [address] => 691-3213 Sit Ave 
        [email] => [email protected] 
        [phone] => 0979 238 0433 
       ) 

      [1] => stdClass Object 
       (
        [ref_id] => 4807 
        [address] => Ap #735-3269 Enim, St. 
        [email] => [email protected] 
        [phone] => (0151) 751 9000 
       ) 

      [2] => stdClass Object 
       (
        [ref_id] => 4934 
        [address] => Ap #423-7150 At, Street 
        [email] => [email protected] 
        [phone] => 0800 547 6093 
       ) 

      [3] => stdClass Object 
       (
        [ref_id] => 4944 
        [address] => 996-9184 Orci. St. 
        [email] => [email protected] 
        [phone] => (0119) 522 6839 
       ) 

      [4] => stdClass Object 
       (
        [ref_id] => 4977 
        [address] => Ap #844-7634 Nunc Rd. 
        [email] => [email protected] 
        [phone] => (016977) 8346 
       ) 

      [5] => stdClass Object 
       (
        [ref_id] => 4990 
        [address] => Ap #330-2369 Pede. St. 
        [email] => [email protected] 
        [phone] => 0920 046 1514 
       ) 

      [6] => stdClass Object 
       (
        [ref_id] => 4992 
        [address] => 344 Nulla Av. 
        [email] => [email protected] 
        [phone] => 0865 632 3945 
       ) 

      [7] => stdClass Object 
       (
        [ref_id] => 5021 
        [address] => 442-7789 Quisque Av. 
        [email] => [email protected] 
        [phone] => 0332 016 9759 
       ) 

      [8] => stdClass Object 
       (
        [ref_id] => 5056 
        [address] => Ap #489-6542 Proin Avenue 
        [email] => [email protected] 
        [phone] => 0352 327 2963 
       ) 

     ) 

) 

我試圖array_merge()但如果有我的父母陣列排列的可變數量...通過谷歌我來array_flatten()方法,但它不能正常工作[我不知道爲什麼]

需要的輸出是

Array(
     [0] => stdClass Object 
      (
       [ref_id] => 249 
       [address] => P.O. Box 496, 5760 Ultrices. Rd. 
       [email] => [email protected] 
       [phone] => 0926 326 7612 
      ) 

     [1] => stdClass Object 
      (
       [ref_id] => 2827 
       [address] => 885 Duis Avenue 
       [email] => [email protected] 
       [phone] => 070 6855 4104 
      ) 

     [2] => stdClass Object 
      (
       [ref_id] => 3228 
       [address] => 861-6767 Mauris St. 
       [email] => [email protected] 
       [phone] => 055 2515 3214 
      ) 

     [3] => stdClass Object 
      (
       [ref_id] => 3327 
       [address] => Ap #815-4752 Tellus. Rd. 
       [email] => [email protected] 
       [phone] => 07624 189445 
      ) 

     [4] => stdClass Object 
      (
       [ref_id] => 3567 
       [address] => 1115 Urna Ave 
       [email] => [email protected] 
       [phone] => (011221) 81949 
      ) 

     [5] => stdClass Object 
      (
       [ref_id] => 4259 
       [address] => P.O. Box 177, 8135 A Rd. 
       [email] => [email protected] 
       [phone] => (014143) 06426 
      ) 

     [6] => stdClass Object 
      (
       [ref_id] => 4547 
       [address] => 759-2274 Purus Rd. 
       [email] => [email protected] 
       [phone] => 076 4327 8034 
      ) 

     [7] => stdClass Object 
      (
       [ref_id] => 4607 
       [address] => 2858 Enim St. 
       [email] => [email protected] 
       [phone] => (01567) 19032 
      ) 

     [8] => stdClass Object 
      (
       [ref_id] => 4660 
       [address] => P.O. Box 131, 3992 Ipsum St. 
       [email] => [email protected] 
       [phone] => 076 4310 5712 
      ) 

     [9] => stdClass Object 
      (
       [ref_id] => 4677 
       [address] => 2813 A, Av. 
       [email] => [email protected] 
       [phone] => 0845 46 49 
      ) 
     [10] => stdClass Object 
      (
       [ref_id] => 4783 
       [address] => 691-3213 Sit Ave 
       [email] => [email protected] 
       [phone] => 0979 238 0433 
      ) 
     ...... 
+0

@Hashem Qolami ......那麼我的目的是增加CI的標籤是可以有我的問題了一些輔助/ CI類的,所以我可以在CI的方式做到這一點... – ITConflux

回答

1

array_merge()將工作,你只要通過主陣列必須循環和合並內陣列。假設你的數組被命名爲$array

$result = array(); 

foreach($array as $values) { 
    $result = array_merge($result, $values); 
} 
print_r($result); 
+0

謝謝。它非常簡單......應該出現在我的腦海裏。我想我應該休息一下,肯定要喝一杯可樂...... – ITConflux

相關問題