How to add the same key values of the two functions to form a new array

Source: Internet
Author: User
How can we add the same key values of these two functions to form a new array ;? Php $ a1 11111, 22222,;,; semicolon extended infinitely $ a explode (;, $ a1); $ b1; semicolon extended infinitely, how to add the same key values of the two functions together to form a new array

 


Output:

Array ( [0] => 10,20,30,40 [1] => 1,2,3,4 ) Array ( [0] => 11111 [1] => 22222 )

What I want to achieve is:

Array ( [0] => 10,20,30,40,11111 [1] => 1,2,3,4,22222)

I tried array_merge_recursive () and it didn't work. could you please help me! I have been studying for several days.
------ Solution --------------------

$ A1 = '10, 20, 30, 40; 1, 2, 3, 4 '; // expanded infinitely with a semicolon $ a = explode ('; ', $ a1); $ b1 = '2017; 22222 '; // The semicolon is infinitely extended. it can be aligned with $ a1 and superimposed $ B = explode ('; ', $ b1); $ c = array_map (null, $, $ B); print_r ($ c );
Array(    [0] => Array        (            [0] => 10,20,30,40            [1] => 11111        )    [1] => Array        (            [0] => 1,2,3,4            [1] => 22222        ))


------ Solution --------------------

$ A1 = '10, 20, 30, 40; 1, 2, 3, 4 '; // expanded infinitely with a semicolon $ a = explode ('; ', $ a1); $ b1 = '2017; 22222 '; // The semicolon is infinitely extended. it can be aligned with $ a1 and superimposed $ B = explode ('; ', $ b1); $ c = array (); foreach ($ a as $ key => $ value) {$ c [] = $ value. ",". $ B [$ key];} echo 'Array ([0] => 10, 20, 30, 40, 11111 [1] => 22222)

The preceding figure shows how to add the same key values of the two functions to form the content of a new array. For more information, see PHP Chinese website (www.php1.cn )!

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.