PHP combined array Append array example _php tutorial

Source: Internet
Author: User
PHP Merging arrays We can use the Array_merge () function, the Array_merge () function, to return an array of unions. The resulting array starts with the first input array parameter, appended in the order in which the array parameters appear later. The form is:

Array Array_merge (array array1 array2...,arrayn)

Here is an example of a php merge array:

1

2$fruits = Array ("Apple", "banana", "pear");

3$numbered = Array ("1", "2", "3");

4$cards = Array_merge ($fruits, $numbered);

5print_r ($cards);

6//Output Results:

7//Array ([0] = Apple [1] = banana [2] = pear [3] = 1 [4] = 2 [5] = 3)

8?>

Append the array with PHP, use array_merge_recursive (), combine the two numbers together, and note that the Array_merge () function is not the same, and that the two arrays of Array_merge () are overwritten when there are duplicates, and Array_ Merge_recursive () is not. Array_merge_recursive () Syntax:

Array array_merge_recursive (array Array1,array array2[...,array Arrayn])

Here is an example of a PHP append array:

1

2$fruit1 = Array ("Apple" = "red", "banana" = "yellow");

3$fruit2 = Array ("pear" = "yellow", "apple" = "green");

4$result = array_merge_recursive ($fruit 1, $fruit 2);

5print_r ($result);

6//Output Results:

7//Array ([Apple] = Array ([0] = + red [1] = = green) [Banana] = yellow [pear] = yellow)

8?>

Apple now points to an array of indexed arrays of two color values.

http://www.bkjia.com/PHPjc/765439.html www.bkjia.com true http://www.bkjia.com/PHPjc/765439.html techarticle PHP Merging arrays We can use the Array_merge () function, the Array_merge () function, to return an array of unions. The resulting array starts with the first input array parameter, followed by the array parameters ...

  • 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.