Considerations for Array_merge functions

Source: Internet
Author: User
array_merge- Merging one or more arrays

Array_merge () Merges the cells of one or more arrays, and the values in an array are appended to the previous array. Returns an array as the result.

If the input array has the same string key name, the value following the key name overrides the previous value. However, if the array contains numeric key names, subsequent values will not overwrite the original values, but are appended to the back.

If only one array is given and the array is a numeric index , the key name is re- indexed in a sequential manner.

array_merge will return NULL if any of the arguments are NULL。

For example:

$array 1 = NULL;
$array 2 = Array (1 = "data");
$result = Array_merge ($array 1, $array 2);
Var_dump ($result); The result is null, so when writing the SQL statement to get the result set, be aware that if (empty ($resut)) {$result =array ();} is assigned an empty array and then merged with the other arrays.

Example :

//The new logic$agent _id=$location _model->where ("id="$location _id' ")->getfield (' agent_id ')); //re-query authorized operators (to exclude authorized merchants)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(); }        //re-search authorized all operators$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 would return null if   any of the arguments is null$TPL _list_merge=Array_merge($TPL _list1,$TPL _list2,$TPL _list3);

The above describes the Array_merge function considerations, including the content of the index, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.