[Single topic]<?php$a=array (3=> "Horse",4=> "Dog");p Rint_r (Array_merge ($a));? >

Source: Internet
Author: User

  1. Array ([0] = Horse [1] = Dog)
  2. Array ([3] = Horse [4] = Dog)

Answer a

Instance

Combine two arrays into an array:

<?php$a1=array ("Red", "green"), $a 2=array ("Blue", "yellow");p Rint_r ( array_merge($a1,$a2) );? >

Running an instance

Definition and usage

The Array_merge () function merges one or more arrays into an array.

Tip: You can enter one or more arrays into the function.

Note: If two or more array elements have the same key name, the last element overrides the other element.

Note: If you enter an array only to the Array_merge () function, and the key name is an integer, the function returns a new array with an integer key name, with the key name re-indexed starting at 0 (see Example 1 below).

Tip: The difference between this function and the array_merge_recursive () function is that it handles two or more arrays of elements with the same key name. Array_merge_recursive () does not overwrite the key name, but instead recursively composes the values of multiple identical key names into an array.

Grammar
Array_merge (array1,array2,array3...)
Parameters Description
Array1 Necessary. Specifies the array.
Array2 Optional. Specifies the array.
Array3 Optional. Specifies the array.
Technical details
return value: Returns the merged array.
PHP version: 4 +
Update log: Since PHP 5.0, this function only accepts parameters of the array type.
More examples of examples 1

Merge two associative arrays into an array:

<?php$a1=array ("A" and "Red", "B" and "green"), $a 2=array ("c" = "Blue", "b" = "yellow");p Rint_r ( array_merge($a1,$a2) ); >

Running an instance

Example 2

Use only one array parameter with an integer key name:

<?php$a=array (3=> "Red",4=> "green");p Rint_r ( array_merge($a) );? >

Running an instance

[Single topic]<?php$a=array (3=> "Horse",4=> "Dog");p Rint_r (Array_merge ($a));? >

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.