PHP combines 2 two-dimensional arrays into a two-dimensional array of 2 solutions _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.