Php uses the array_merge () function to merge two arrays. array_merge array _ PHP Tutorial

Source: Internet
Author: User
Tags array example
Php uses the array_merge () function to merge two arrays: array_merge array. Php uses the array_merge () function to merge two arrays. the array_merge array example describes how php uses the array_merge () function to merge two arrays. I would like to share with you how to use the array_merge () function to merge two arrays in php. the array_merge array

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.

$first = array("aa", "bb", "cc");$second = array(11,22,33);$third = array_merge($first, $second); foreach ( $third as $val ) { print "$val
";}

The preceding code execution result is as follows:

The output is an array with ('aa', '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.

The merge () function merges two arrays. array_merge array This article describes how php merges two arrays through the array_merge () function. I will share it with you for your reference...

Related Article

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.