2014-01-15 68 views
0

我有兩個獨立的數組。現在我想用現有的兩個數組創建多維數組。 這是我的兩個獨立陣列 -使用php創建並推送多維數組中的值

Array 
(
[0] => 11 
[1] => 22 
[2] => 33 
[3] => 44 
) 

------------------- 
    Array 
(
[0] => 555 
[1] => 666 
[2] => 777 
[3] => 888 
) 

我想導致多維數組,那就是 -

Array 
(



[0] => Array 
    (
     [0] => 11 
     [demoid] => 11 
     [1] => 555 
     [demovalue] => 555 
    ) 
    [1] => Array 
    (
     [0] => 22 
     [demoid] => 22 
     [1] => 666 
     [demovalue] => 666 
    ) 
    [2] => Array 
    (
     [0] => 33 
     [demoid] => 33 
     [1] => 777 
     [demovalue] => 777 
    ) 
) 
+0

你有一些代碼實際上試圖將它們合併?你至少應該嘗試 – max

+0

爲什麼你需要每個數值的數字和命名鍵? – Barmar

回答

2

只是一個循環並增加值到一個新的陣列 - 我不明白爲什麼你會努力這樣做...

$new_array = array(); 
foreach($array1 as $key => $val) { 
    $new_array[] = array( 0 => $val, 
          'demoid' => $val, 
          1 => $array2[$key], 
          'demovalue' => $array2[$key]); 
} 
+0

謝謝瑞安..它運行。 – user3197889