array_merge — Merge one or more arrays
array_merge() Merges the cells of one or more arrays, and the values in one array are appended to the previous array. Returns the resulting array.
If the input array has the same string key name, the value after the key name will overwrite the previous value. However, if the array contains numeric key names, the subsequent value will not overwrite the original value, but will be appended to it.
If only an array is given and the array is numerically indexed, the keys will be re-indexed consecutively.
<code><span class="html">array_merge will return NULL if any of the arguments are NULL。</span>
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); ($result); the result is NULL, so when writing SQL statements to obtain the result set, pay attention to if(empty($resut)){$result=array();} assign an empty array and then compare it with other arrays merge.
Example:
<span>//</span><span>新的逻辑</span> <span>$agent_id</span>=<span>$location_model</span>->where("id='<span>$location_id</span>'")->getField('agent_id'<span>); </span><span>//</span><span>再查询已授权的运营商(要排除授权商家)</span> <span>if</span>(!<span>empty</span>(<span>$agent_id</span><span>)){ </span><span>$tpl_list2</span>=<span>$tpl_model</span>->where("status=1 and agent_range=2 and agent_id in (<span>$agent_id</span>) and supplier_id=''")->field(<span>$field</span>)->order('id desc')-><span>select(); } </span><span>if</span>(<span>empty</span>(<span>$tpl_list2</span><span>)){ </span><span>$tpl_list2</span>=<span>array</span><span>(); } </span><span>//</span><span>再查询授权全部运营商</span> <span>$tpl_list3</span>=<span>$tpl_model</span>->where("status=1 and agent_range=1")->field(<span>$field</span>)->order('id desc')-><span>select(); </span><span>if</span>(<span>empty</span>(<span>$tpl_list3</span><span>)){ </span><span>$tpl_list3</span>=<span>array</span><span>(); } <span>//<span>array_merge will return NULL if any of the arguments are NULL</span></span> </span><span>$tpl_list_merge</span>=<span>array_merge</span>(<span>$tpl_list1</span>,<span>$tpl_list2</span>,<span>$tpl_list3</span>);