array_merge — 合并一個(gè)或多個(gè)數(shù)組
array_merge() 將一個(gè)或多個(gè)數(shù)組的單元合并起來(lái),一個(gè)數(shù)組中的值附加在前一個(gè)數(shù)組的后面。返回作為結(jié)果的數(shù)組。
如果輸入的數(shù)組中有相同的字符串鍵名,則該鍵名后面的值將覆蓋前一個(gè)值。然而,如果數(shù)組包含數(shù)字鍵名,后面的值將不會(huì)覆蓋原來(lái)的值,而是附加到后面。
如果只給了一個(gè)數(shù)組并且該數(shù)組是數(shù)字索引的,則鍵名會(huì)以連續(xù)方式重新索引。
array_merge will return NULL if any of the arguments are NULL。
例如:
$array1 = NULL;
$array2 = array(1 => "data");
$result = array_merge($array1, $array2);
var_dump($result);結(jié)果為NULL,所以在寫(xiě)SQL語(yǔ)句獲取結(jié)果集的時(shí)候要注意,if(empty($resut)){$result=array();} 賦值為空數(shù)組后再和其他的數(shù)組進(jìn)行合并。
例子:
//新的邏輯 $agent_id=$location_model->where("id='$location_id'")->getField('agent_id'); //再查詢(xún)已授權(quán)的運(yùn)營(yíng)商(要排除授權(quán)商家) 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(); } //再查詢(xún)授權(quán)全部運(yùn)營(yíng)商 $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);
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注