Php uses the array_merge () function to merge two arrays.

Source: Internet
Author: User

Php uses the array_merge () function to merge two arrays.

This article describes how to merge two Arrays Using the array_merge () function in php. The example shows how to use the array_merge () function in php to merge arrays. For more information, see

 

 

This example describes how php combines two arrays through the array_merge () function. Share it with you for your reference. The specific analysis is as follows:

Php uses the array_merge () function to merge two arrays. array_merge () is a php function used to combine two or more arrays. The last array is appended to the back of the previous array, and returns an array of results. It accepts two or more arrays and returns an array containing all elements.

?

1

2

3

4

5

6

7

$ First = array ("aa", "bb", "cc ");

$ Second = array (11,22, 33 );

$ Third = array_merge ($ first, $ second );

 

Foreach ($ third as $ val ){

Print "$ val <br/> ";

}

The preceding code execution result is as follows:

?

1

The output is an array with ('A', 'bb ', 'cc', 11, 22, 33)

Note: If the input array has the same string key, this key will overwrite the previous one. However, if the array contains a number key, the subsequent values will not overwrite the original values, but will be appended.

I hope this article will help you with php programming.

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.