国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

array_diff函數的注意事項

2019-11-14 14:36:08
字體:
來源:轉載
供稿:網友

  array_diff — 計算數組的差集

  說明:

  array array_diff ( array $array1 , array $array2 [, array $... ] )  對比返回在 array1 中但是不在 array2 及任何其它參數數組中的值。注意鍵名保留不變。

  注意:本函數只檢查了多維數組中的一維。如果想比較更深的維度需要另寫一個函數,今天的工作就遇到了這樣的需求,所以寫了一個函數來比較更深的維度。

  

<?phpheader("Content-type:text/html;charset=utf-8");$json1='{ "filedir":"default", "pages" : [ { "name" : "首頁", "blocks":[ { "name":"頭部標題欄", "blocktype":"title_bar", "settings":{ "is_show":true, "bg_color":"#1eb7a4", "content_switch":true, "content":"", "bg_url":"", "color":"#fff", "border_bottom_color":"", "border_bottom_width":"0" } }, { "name":"頭部廣告圖", "blocktype":"ad_picture", "settings":{ "is_show":true, "bg_url":"" } }, { "name":"廣告", "blocktype":"ad", "settings":{ "is_show":true, "number":5, "show_type":"scroll" } }, { "name":"菜單", "blocktype":"menu", "settings":{ "is_show":true, "bg_color":"#fff", "color":"#1eb7a4" } }, { "name":"個人中心", "blocktype":"personal_center", "settings":{ "is_show":true, "bg_color":"#fff", "color":"#1eb7a4" } }, { "name":"上網按鈕", "blocktype":"online_button", "settings":{ "is_show":true, "offline_bg_url":"", "online_bg_url":"" } } ] }, { "name" : "登錄頁", "blocks":[ { "name":"頁面背景", "blocktype":"page_bg", "settings":{ "is_show":true, "bg_url":"", "bg_color":"" } }, { "name":"logo圖", "blocktype":"logo", "settings":{ "is_show":true, "bg_url":"" } }, { "name":"登錄模塊", "blocktype":"login", "settings":{ "is_show":true, "success_url":"" } } ] }, { "name" : "認證過程頁", "duration":"5", "blocks":[ { "name":"頁面背景", "blocktype":"page_bg", "settings":{ "is_show":false, "bg_url":"" } }, { "name":"登錄動畫", "blocktype":"login_animate", "settings":{ "is_show":true, "bg_url":"" } } ] }, { "name" : "登錄成功頁", "blocks":[ { "name":"頭部廣告圖", "blocktype":"ad_picture", "settings":{ "is_show":true, "bg_url":"" } }, { "name":"成功頁app", "blocktype":"apps", "settings":{ "is_show":true } }, { "name":"成功頁提示信息", "blocktype":"success_t;$json2='{ "filedir":"default", "pages" : [ { "name" : "首頁", "blocks":[ { "name":"頭部標題欄", "blocktype":"title_bar", "settings":{ "is_show":true, "bg_color":"#1eb7a4", "content_switch":true, "content":"", "bg_url":"", "color":"#fff", "border_bottom_color":"", "border_bottom_width":"0" } }, { "name":"頭部廣告圖", "blocktype":"ad_picture", "settings":{ "is_show":true, "bg_url":"" } }, { "name":"廣告", "blocktype":"ad", "settings":{ "is_show":true, "number":5, "show_type":"scroll" } }, { "name":"菜單", "blocktype":"menu", "settings":{ "is_show":true, "bg_color":"#fff", "color":"#1eb7a4" } }, { "name":"個人中心", "blocktype":"personal_center", "settings":{ "is_show":true, "bg_color":"#fff", "color":"#1eb7a4" } }, { "name":"上網按鈕", "blocktype":"online_button", "settings":{ "is_show":true, "offline_bg_url":"", "online_bg_url":"" } } ] }, { "name" : "登錄頁", "blocks":[ { "name":"頁面背景", "blocktype":"page_bg", "settings":{ "is_show":true, "bg_url":"", "bg_color":"" } }, { "name":"logo圖", "blocktype":"logo", "settings":{ "is_show":true, "bg_url":"" } }, { "name":"登錄模塊", "blocktype":"login", "settings":{ "is_show":true, "success_url":"" } } ] }, { "name" : "認證過程頁", "duration":"5", "blocks":[ { "name":"頁面背景", "blocktype":"page_bg", "settings":{ "is_show":false, "bg_url":"" } }, { "name":"登錄動畫", "blocktype":"login_animate", "settings":{ "is_show":true, "bg_url":"" } } ] }, { "name" : "登錄成功頁", "blocks":[ { "name":"頭部廣告圖", "blocktype":"ad_picture", "settings":{ "is_show":true, "bg_url":"" } }, { "name":"成功頁app", "blocktype":"apps", "settings":{ "is_show":true } }, { "name":"成功頁提示信息", "blocktype":"success_tips", "settings":{ "is_show":false, "color":"#fff", "content":"" } } ] }, { "name" : "廣告細覽頁", "blocks":[ { "name":"頭部標題欄", "blocktype":"title_bar", "settings":{ "is_show":true, "bg_color":"#1eb7a4", "content_switch":true, "content":"", "bg_url":"", "color":"#fff", "border_bottom_color":"", "border_bottom_width":"0" } } ] } ] }';$array1=json_decode($json1,true);$array2=json_decode($json2,true);function array_recursive_diff($array1, $array2) {    $result = array();    foreach ($array1 as $key1 => $value1) {        if (array_key_exists($key1, $array2)) {            if (is_array($value1)) {                $diff = array_recursive_diff($value1, $array2[$key1]);                if (count($diff)) { //這個位置進行優化:判斷!empty($diff)                    $result[$key1] = $diff;                }            } else {                if ($value1 != $array2[$key1]) {                    $result[$key1] = $value1;                }            }        } else {            $result[$key1] = $value1;        }    }    return $result;}$result=array_recursive_diff($array1, $array2);echo '<;var_dump($result);if(empty($result)){    echo '完全相同';}else{    echo '完全不相同';}

 

  

  

  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 抚松县| 卢龙县| 大渡口区| 宁化县| 比如县| 高尔夫| 灌云县| 彭泽县| 乾安县| 榆社县| 东至县| 乌兰浩特市| 丹凤县| 西丰县| 大英县| 阜新市| 大田县| 嘉鱼县| 唐海县| 讷河市| 杭州市| 昌图县| 永春县| 黑龙江省| 政和县| 湘潭市| 沾益县| 简阳市| 华安县| 普格县| 南陵县| 大新县| 万载县| 南城县| 高碑店市| 汾西县| 丘北县| 扎囊县| 芒康县| 旌德县| 麦盖提县|