1.array_merge () Merge
Example
The code is as follows |
|
$array = Array (' A ' => ' BB '); $array 2 = Array (' B ' => ' cc '); $array 3 = Array_merge ($array, $array 2); Output results are Array ([a] => BB [b] => cc) |
It's all right because it's all arrays, and if we're going to set the $array not an array, see what happens.
The code is as follows |
|
$array = 1;//array (' A ' => ' BB '); $array 2 = Array (' B ' => ' cc '); $array 3 = Array_merge ($array, $array 2); Print_r ($array 3);
|
Post-run results
Warning:array_merge () [Function.array-merge]: Argument #1 is not ' an array in e:test1.php ' line 4
Tell us that we have to have an array, then I have a number of ways to solve it,
1. Use Is_array () to judge, but found that if the combination of arrays more than a reasonable judge, later found that you can convert the data type
The code is as follows |
|
$array = 1;//array (' A ' => ' BB '); $array 2 = Array (' B ' => ' cc '); $array 3 = Array_merge ((array) $array, (array) $array 2); Print_r ($array 3); The output is not an error Array ([0] => 1 [b] => cc) |
He automatically converts the number 1 into an array, so be sure to pay attention to these details when you use it.