Title: The following 2 two-dimensional arrays
1
$a =array (0 = = Array (id = 66,class_name = www.iiwnet.com), 1 = = Array (id = = 67,class_name = Linux));
2
$b =array (0 = = Array (class_count=> 8), 1 = = Array (Class_count = 2));
Two array contents as above, how to merge $ A and $b into a new two-dimensional array, requiring the contents of the new array as follows:
1
Array (0 = = Array (id = = 66,class_name = www.iiwnet.com,class_count=> 8), 1 = = Array (id = = 67,class_name = > Linux, Class_count = 2));
Someone must have met this topic. 2 solutions are given in the crowd today.
The following code is provided by PHP tutorial Network original
01
Method One:
02
03
function Arrpreg () {
04
$a =array (0 = = Array (id = 66,class_name = www.iiwnet.com), 1 = = Array (id = = 67,class_name = Linux));
05
$b =array (0 = = Array (class_count=> 8), 1 = = Array (Class_count = 2));
06
$arr = Array ();
07
foreach ($a as $k = = $r) {
08
foreach ($r as $k 1 = $r 1) {
09
$arr [$k] [$k 1] = $r 1;
10
}
11
}
12
foreach ($b as $k = = $r) {
13
foreach ($r as $k 1 = $r 1) {
14
$arr [$k] [$k 1] = $r 1;
15
}
16
}
17
return $arr;
18
}
19
$ar = Arrpreg ();
20
Echo '
';
21st
Print_r ($ar);
22
Echo '
';
23
?>
24
25
Method Two:
26
27
$a = Array (0 = = Array (id = = 66,class_name = www.iiwnet.com), 1 = = Array (id = = 67,class_name = Linux));
28
$b = Array (0 = = Array (class_count=> 8), 1 = = Array (Class_count = 2));
29
$arr = Array ();
30
foreach ($a as $k = = $r) {
31
$arr [] = Array_merge ($r, $b [$k]);
32
}
33
Echo '
';
34
Print_r ($arr);
35
Echo '
';
http://www.bkjia.com/PHPjc/477952.html www.bkjia.com true http://www.bkjia.com/PHPjc/477952.html techarticle title: There are 2 two-dimensional arrays of 1 $a =array (0 = array (id = 66,class_name = www.iiwnet.com), 1 = array (id = 67,class_name = Linux)); 2 $b =a Rray (0 = array (class_count= 8), 1 = array ...