検索
ホームページphp教程php手册array_merge函数的注意事项,array_merge函数

array_merge函数的注意事项,array_merge函数

Jun 13, 2016 am 08:49 AM
arraymerge関数マージ複数意思配列予防

array_merge函数的注意事项,array_merge函数

  array_merge — 合并一个或多个数组 

  array_merge() 将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。返回作为结果的数组。

  如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值。然而,如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到后面。

  如果只给了一个数组并且该数组是数字索引的,则键名会以连续方式重新索引。

  <span class="html">array_merge will return NULL if any of the arguments are NULL。</span>

  例如:

    $array1 = NULL;
    $array2 = array(1 => "data");
    $result = array_merge($array1, $array2);

    var_dump($result);结果为NULL,所以在写SQL语句获取结果集的时候要注意,if(empty($resut)){$result=array();} 赋值为空数组后再和其他的数组进行合并。

  例子

        <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>);

 

    

       
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

SublimeText3 Linux 新バージョン

SublimeText3 Linux 新バージョン

SublimeText3 Linux 最新バージョン

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

EditPlus 中国語クラック版

EditPlus 中国語クラック版

サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません