Considerations for Array_diff functions

Source: Internet
Author: User
Tags diff
array_diff- Calculating the difference set of an array

Description

Array array_diff ( array $array1 , array $array2 [, array $... ]) compares the values returned in array1 but not in array2 any other parameter array 。 Note The key name remains unchanged.

Note: This function examines only one dimension in a multidimensional array. If you want to compare a deeper dimension to another function, today's work meets the need, so write a function to compare the deeper dimensions.

 PhpHeader("Content-type:text/html;charset=utf-8");$json 1= ' {"Filedir": "Default", "pages": [{"Name": "Home", "blocks": [{"Name": "Header title bar", "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": "Head ad", "Blocktype": "Ad_picture", "settings": {"Is_show":  True, "Bg_url": ""}, {"Name": "Ad", "Blocktype": "Ad", "Settings": {"is_show": True, "number": 5, "Show_type": "Scroll"}}, {"Name": "Menu", "Blocktype": "Menus", "settings": {"is_show": True, "Bg_color": "#fff", "Color": "#1eb7a4"}}, {"name": "Personal Center" "," Blocktype ":" Personal_center "," settings ": {" is_show ": True," Bg_color ":" #fff "," Color ":" #1eb7a4 "}}, {" name ":" Internet button "," Blocktype ":" Online_button "," settings ": {" is_show ": True," Offline_bg_url ":" "," Online_bg_url ":" "}}]}, {" Name ":" Login Page "," blocks ": [{" Name ":" Page Background "," Blocktype ":" PAGE_BG "," settings ": {" is_show ": True," Bg_url ":" "," Bg_color ":" "}}, {" N Ame ":" Logo map "," Blocktype ":" Logo "," Settings ":{"Is_show": True, "Bg_url": ""}}, {"name": "Login Module", "Blocktype": "Login", "settings": {"is_show": True, "Success_url": ""}}  ]}, {"Name": "Authentication Process Page", "duration": "5", "blocks": [{"Name": "Page Background", "Blocktype": "PAGE_BG", "settings": {"Is_show": false,  "Bg_url": ""}}, {"Name": "Logon Animation", "Blocktype": "Login_animate", "settings": {"is_show": True, "Bg_url": ""}}]}, {"Name" : "Login Success Page", "blocks": [{"Name": "Head ad Map", "Blocktype": "Ad_picture", "settings": {"is_show": True, "Bg_url": ""}}, {"Name": "Success page App", "Blocktype": "Apps", "Settings": {"Is_show": true}, {"Name": "Success page Prompt", "Blocktype": "Success_tips", " Settings ": {" Is_show ": false," color ":" #fff "," Content ":" "}}]}, {" Name ":" Ad page "," blocks ": [{" Name ":" Header title bar "," block Type ":" Title_bar "," settings ": {" is_show ": True," Bg_color ":" #1eb7a4 "," Content_switch ": True," content ":" "," Bg_url ": "", "Color": "#fff", "Border_bottom_color": "", "Border_bottom_width": "0"}]}]} ';$json 2= ' {"Filedir": "Default", "pages": [{"Name": "Home", "blocks": [{"Name": "Header title bar", "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": "Head ad", "Blocktype": "Ad_picture", "settings": {"Is_show":  True, "Bg_url": ""}, {"Name": "Ad", "Blocktype": "Ad", "Settings": {"is_show": True, "number": 5, "Show_type": "Scroll"}}, {"Name": "Menu", "Blocktype": "Menus", "settings": {"is_show": True, "Bg_color": "#fff", "Color": "#1eb7a4"}}, {"name": "Personal Center" "," Blocktype ":" Personal_center "," settings ": {" is_show ": True," Bg_color ":" #fff "," Color ":" #1eb7a4 "}}, {" name ":" Internet button "," Blocktype ":" Online_button "," settings ": {" is_show ": True," Offline_bg_url ":" "," Online_bg_url ":" "}}]}, {" Name ":" Login Page "," blocks ": [{" Name ":" Page Background "," Blocktype ":" PAGE_BG "," settings ": {" is_show ": True," Bg_url ":" "," Bg_color ":" "}}, {" N Ame ":" Logo map "," Blocktype ":" Logo "," Settings ":{"Is_show": True, "Bg_url": ""}}, {"name": "Login Module", "Blocktype": "Login", "settings": {"is_show": True, "Success_url": ""}}  ]}, {"Name": "Authentication Process Page", "duration": "5", "blocks": [{"Name": "Page Background", "Blocktype": "PAGE_BG", "settings": {"Is_show": false,  "Bg_url": ""}}, {"Name": "Logon Animation", "Blocktype": "Login_animate", "settings": {"is_show": True, "Bg_url": ""}}]}, {"Name" : "Login Success Page", "blocks": [{"Name": "Head ad Map", "Blocktype": "Ad_picture", "settings": {"is_show": True, "Bg_url": ""}}, {"Name": "Success page App", "Blocktype": "Apps", "Settings": {"Is_show": true}, {"Name": "Success page Prompt", "Blocktype": "Success_tips", " Settings ": {" Is_show ": false," color ":" #fff "," Content ":" "}}]}, {" Name ":" Ad page "," blocks ": [{" Name ":" Header title bar "," block Type ":" Title_bar "," settings ": {" is_show ": True," Bg_color ":" #1eb7a4 "," Content_switch ": True," content ":" "," Bg_url ": "", "Color": "#fff", "Border_bottom_color": "", "Border_bottom_width": "0"}]}]} ';$array 1=json_decode ($json 1,true);$array 2=json_decode ($json 2,true);functionArray_recursive_diff ($array 1,$array 2) {    $result=Array(); foreach($array 1 as$key 1=$value 1) {        if(array_key_exists($key 1,$array 2)) {            if(Is_array($value 1)) {                $diff= Array_recursive_diff ($value 1,$array 2[$key 1]); if(Count($diff)) {                    $result[$key 1] =$diff; }            } Else {                if($value 1!=$array 2[$key 1]) {                    $result[$key 1] =$value 1; }            }        } Else {            $result[$key 1] =$value 1; }    }    return$result;}$result=array_recursive_diff ($array 1,$array 2);Echo'
'; Var_dump ($result); if (empty($result)) {    echo ' is exactly the same ';} Else {    echo ' is completely different ';}

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

  • Related Article

    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.