Php array combination

Source: Internet
Author: User
I feel like I haven't written an article for a long time. Recently, the pressure is huge. Let's talk about php arrays today. for example, I have two arrays. The format is as follows:

I feel like I haven't written an article for a long time. Recently, the pressure is huge. Let's talk about php arrays today. for example, I have two arrays. The format is as follows:

 

$ List = array ('1' => 'A', '2' => 'B', '3' => 'C ');
$ List2 = array ('1' => '1', '2' => '2', '3' => '3 ');


Array (3 ){
[1] =>
String (1) ""
[2] =>
String (1) "B"
[3] =>
String (1) "c"
}
Array (3 ){
[1] =>
String (1) "1"
[2] =>
String (1) "2"
[3] =>
String (1) "3"
}

So how do I want him to make up this format?

Array (6 ){
[0] =>
String (1) ""
[1] =>
String (1) "1"
[2] =>
String (1) "B"
[3] =>
String (1) "2"
[4] =>
String (1) "c"
[5] =>
String (1) "3"
}

 

I don't know if you have encountered this problem in the project. First, let's look at the implementation code:

$ List = array ('1' => 'A', '2' => 'B', '3' => 'C ');
$ List2 = array ('1' => '1', '2' => '2', '3' => '3 ');
Var_dump ($ list );
Var_dump ($ list2 );
$ Size = count ($ list)> count ($ list2 )? Count ($ list): count ($ list2); // retrieves the array loop with the most elements
$ Arr = array ();
For ($ I = 1; $ I <= $ size; $ I ++ ){
Array_push ($ arr, $ list [$ I]); // Press the array into a new variable.
Array_push ($ arr, $ list2 [$ I]); // Press the array into a new variable.
}
Var_dump ($ arr );
?>

 

OK.

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.