Home > Backend Development > PHP Tutorial > Things to note about array_merge function, array_merge function_PHP tutorial

Things to note about array_merge function, array_merge function_PHP tutorial

WBOY
Release: 2016-07-12 09:03:25
Original
1083 people have browsed it

Notes on array_merge function, array_merge function

 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>);
Copy after login

  ​ ​ ​

http://www.bkjia.com/PHPjc/1080770.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1080770.htmlTechArticleNotes on array_merge function, array_merge function array_merge merges one or more arrays array_merge() merges one or more arrays The cells are combined, and the values ​​in an array are appended...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template