: This article mainly introduces considerations for the array_merge function. if you are interested in the PHP Tutorial, please refer to it. Array_merge-merge one or more arrays
Array_merge () combines the units of one or more arrays. the values in an array are appended to the values of the previous array. Returns an array of results.
If the input array contains the same string key name, the value after the key name overwrites the previous value. However, if the array contains a number key nameNoOverwrite the original value, but append it to the end.
If only one array is given and the array is a numberIndex, The key name will be reconnected in a continuous mannerIndex.
array_merge will return NULL if any of the arguments are NULL。
For example:
$ Array1 = NULL;
$ Array2 = array (1 => "data ");
$ Result = array_merge ($ array1, $ array2 );
Var_dump ($ result); the result is NULL. Therefore, when writing an SQL statement to obtain the result set, note that if (empty ($ resut) {$ result = array ();} the value is an empty array and then merged with other arrays.
Example:
// New Logic $ agent_id = $ location_model-> where ("id = '$ location_id'")-> getField ('Agent _ id '); // query the authorized carrier (to exclude authorized merchants) if (! Empty ($ agent_id) {$ tpl_list2 = $ tpl_model-> where ("status = 1 and agent_range = 2 and agent_id in ($ agent_id) and supplier_id = ''") -> field ($ field)-> order ('Id desc')-> select ();} if (empty ($ tpl_list2) {$ tpl_list2 = array ();} // query and authorize all carriers $ tpl_list3 = $ tpl_model-> where ("status = 1 and agent_range = 1")-> field ($ field) -> order ('Id desc ')-> select (); if (empty ($ tpl_list3) {$ tpl_list3 = array ();} // array_merge will return NULL if any of the arguments are NULL $ tpl_list_merge = array_merge ($ tpl_list1, $ tpl_list2, $ tpl_list3 );
The above describes the precautions for the array_merge function, including the index content, and hope to help those who are interested in the PHP Tutorial.