PHP Implementation method of merging 2 numeric key array values

Source: Internet
Author: User
This article mainly introduces the implementation of PHP to merge 2 numeric key array value method, involving PHP for array traversal, judgment, conversion and other related operations skills, the need for friends can refer to the following

In this paper, we describe the simple implementation of PHP to merge 2 numeric key array value method. Share to everyone for your reference, as follows:

First, we need to understand a basic point: PHP combined array + and Array_merge analysis of the difference


<?php/** * PHP merges 2 numeric key array values * * @param array $arr 1 * @param array $arr 2 * @return array */function new_array_merge ($arr 1, $arr 2) {  if (!is_array ($arr 1) | |!is_array ($arr 2))  {    return array ();  }  $arr = Array_flip ($arr 1) + Array_flip ($arr 2);  Return Array_keys ($arr);} $arr 1 = array (' AA ', ' BB ', ' cc '), $arr 2 = Array (' Aa2 ', ' BB ', ' cc2 '); $arr = New_array_merge ($arr 1, $arr 2);p Rint_r ($arr);


Output:


Array (  [0] = AA  [1] = BB  [2] = = CC  [3] = Aa2  [4] = CC2)



Related recommendations:

A detailed description of how PHP inserts elements before the key specified by the associated array

PHP implementation method for getting single-column values in an array

How PHP uses Str_replace to replace multidimensional arrays


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.