2017-04-07 106 views
-1

我有兩個陣列具有不同大小如何使用php比較兩個不同大小的數組?

Array1 ([26] => DJ [24] => APOLLO [36] => KLE [30] => Ajay [34] => RAJ [1] => Raj [2] => Globe). 

Array2([0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => [18] => [19] => [20] => [21] => [22] => [23] => [24] => [25] => [26] => [27] => [28] => [29] => [30] => [31] => [32] => [33] => [34] => [35] => [36] =>) 

怎樣比較兩個陣列具有不同的尺寸和分配在ARRAY2在特定位置數組1值

+0

編輯闡述 – Khaleel

+0

你真正想要的是什麼?這是不是足夠的東西讓你的答案 –

+0

@Ashok Khot如果兩個數組的大小不同,則根據array1元素鍵將array1的元素分配到array2中?你想要這個嗎? –

回答

0

@Ashok Khot簡單地使用的foreach()如下面:

<?php 
$Array1 = array(26 => "DJ", 24 => "APOLLO", 36 => "KLE", 30 => "Ajay", 34 => "RAJ", 1 => "Raj", 2 => "Globe"); 
$Array2 = array(0 => null, null, 1 => null, 2 => null, 3 => null, 4 => null, 5 => null, 6 => null, 7 => null, 8 => null, 9 => null, 10 => null, 11 => null, 12 => null, 13 => null, 14 => null, 15 => null, 16 => null, 17 => null, 18 => null, 19 => null, 20 => null, 21 => null, 22 => null, 23 => null, 24 => null, 25 => null, 26 => null, 27 => null, 28 => null, 29 => null, 30 => null, 31 => null, 32 => null, 33 => null, 34 => null, 35 => null, 36 => null); 
foreach ($Array1 as $key => $value) { 
    $Array2[$key] = $value; 
} 
echo "<pre>"; 
print_r($Array2); 
+0

謝謝@Bunker男孩它的作品 –

+0

@Ashok Khot歡迎你繼續它(y) –