Home >Backend Development >PHP Tutorial >Use of array_merge function

Use of array_merge function

WBOY
WBOYOriginal
2016-07-29 09:00:541222browse

<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了。
这个拼接函数在其中一个为空的时候,会整体为空,需要做拼接的判断!

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了array_merge 函数的使用,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn