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