<code><span>$condition</span>[<span>'is_own'</span>] = <span>0</span>; <span>$condition</span>[<span>'is_pass'</span>] = <span>0</span>; <span>$notDeal_user_list</span> = <span>array</span>(); <span>foreach</span>(<span>$temp</span><span>as</span><span>$k</span>=><span>$v</span>){ <span>$condition</span>[<span>'route_id'</span>] = <span>$v</span>[<span>'route_id'</span>]; <span>$temp_array</span> = <span>$route_person_model</span>->where(<span>$condition</span>)->field(<span>'user_id,route_id,id'</span>)->select(); <span>if</span>(!<span>empty</span>(<span>$temp_array</span>)){ <span>$notDeal_user_list</span> = array_merge(<span>$notDeal_user_list</span>,<span>$temp_array</span>); } <span>//array_merge函数 在其中一个为空的时候最后结果为空</span><span>//把不同行程的用户信息都拼接起来</span> } <span>// var_dump($notDeal_user_list); die();</span><span>foreach</span>(<span>$notDeal_user_list</span><span>as</span><span>$k</span>=><span>$v</span>){ <span>$notDeal_user_list</span>[<span>$k</span>][<span>'route_info'</span>] = getRouteInfo(<span>$v</span>[<span>'route_id'</span>]); <span>$notDeal_user_list</span>[<span>$k</span>][<span>'user_info'</span>] = getUserInfo(<span>$v</span>[<span>'user_id'</span>]); } <span>$this</span>->notDeal_user_list = <span>$notDeal_user_list</span>;</code>
在没有加if判断是否为空之前,数组整个都是null,加了之后就OK了。
这个拼接函数在其中一个为空的时候,会整体为空,需要做拼接的判断!
以上就介绍了array_merge 函数的使用,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。