The array_merge () function merges arrays in php. You can combine multiple numbers into an array without changing the value of the original array (www.111cn.net, but today, when I use array_merge to merge arrays
The array_merge () function merges arrays in php. You can combine multiple numbers into an array without changing the value of the original array (www.111cn.net, but today, when I use array_merge to merge arrays
1. array_merge () Merge
Example
$ Array = array ('A' => 'bb'); $ array2 = array ('B' => 'cc'); $ array3 = array_merge ($ array, $ array2); the output result is Array ([a] => bb [B] => cc)
The above is no problem because it is an array. Let's set $ array as an array to see what's going on.
$ Array = 1; // array ('A' => 'bb '); $ array2 = array (' B '=> 'cc '); $ array3 = array_merge ($ array, $ array2); print_r ($ array3 );
Running result
Warning: array_merge () [function. array-merge]: Argument #1 is not an array in E: test1.php on () line 4
It tells us that an array is required, so there are many ways to solve this problem ,,
1. I used is_array () to determine the data type. However, I found that it is unreasonable to merge multiple arrays. Later I found that the data type can be converted.
$ Array = 1; // array ('A' => 'bb '); $ array2 = array (' B '=> 'cc '); $ array3 = array_merge (array) $ array, (array) $ array2); print_r ($ array3 ); array ([0] => 1 [B] => cc)
He automatically converts number 1 to an array, so you must pay attention to these details when using it.