PHP uses the array_merge method to rearrange the objects under the array. array_merge array _ PHP Tutorial

Source: Internet
Author: User
Tags array example
PHP uses the array_merge method to re-arrange the objects under the array, which is the array_merge array. PHP uses the array_merge method to re-arrange the objects in the array. the array_merge array example describes how PHP uses array_merge to re-arrange objects in the array. Share it with you for your reference. PHP uses the array_merge method to re-arrange the array objects. the array_merge array

The example in this article describes how PHP uses array_merge to rearrange the objects under the array. Share it with you for your reference. The details are as follows:

An array_unique is used to remove the duplicates in an array. However, it is found that the subscript retains the subscript of the original array. However, php uses the for loop and requires the subscript to be neat, so array_merge can solve this problem by searching for the method to rearrange the objects under the array.

The array_merge () function combines two or more numbers into an array.

If the key name already exists, the key value of the key is the value corresponding to the last key name (the subsequent one overwrites the previous one ). If the array is a digital index, the key name is re-indexed continuously.

Note: If you only input an array to the array_merge () function and the key name is an integer, the function returns a new array with an integer key name, its key name starts from 0 and is re-indexed. (See example 2)

Syntax:

Array_merge (array1, array2, array3 ...)

Parameters Description
Array1 Required. The first input array.
Array2 Required. The second input array.
Array3 Optional. Multiple input arrays that can be specified.

Example 1

<?php$a1=array("a"=>"Horse","b"=>"Dog");$a2=array("c"=>"Cow","b"=>"Cat");print_r(array_merge($a1,$a2));?>

Output:

Array ([a] => Horse [B] => Cat [c] => Cow)

Example 2

Use only one array parameter:

<?php$a=array(3=>"Horse",4=>"Dog");print_r(array_merge($a));?>

Output:

Array ([0] => Horse [1] => Dog)

I hope this article will help you with php programming.

Examples in this article describes how PHP uses array_merge to rearrange the objects under the array. Share it with you for your reference ....

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.