Questions about the ARRAY_DIFF_UASSOC

Source: Internet
Author: User
Source:


  
    $b)? 1:-1;  }  $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");  $array2 = array("a" => "green", "yellow", "red");  $result = array_diff_uassoc($array1, $array2, "key_compare_func");  print_r($result);

Results:

string(1) "b"string(1) "a"=====1string(1) "b"string(1) "c"=====2int(0)string(1) "b"=====3string(1) "a"int(0)=====4int(0)string(1) "a"=====5int(1)int(0)=====6string(1) "a"int(0)=====7string(1) "a"string(1) "a"=====8int(0)string(1) "a"=====8int(0)int(0)=====9string(1) "b"string(1) "a"=====9string(1) "b"int(0)=====10string(1) "b"int(1)=====11string(1) "c"string(1) "a"=====12string(1) "c"int(0)=====13string(1) "c"int(1)=====14Array(    [b] => brown    [c] => blue    [0] => red)

Excuse me:

对于这个函数,他的比较原理是什么?为什么要进行14次比较?

Reply content:

Source:


  
    $b)? 1:-1;  }  $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");  $array2 = array("a" => "green", "yellow", "red");  $result = array_diff_uassoc($array1, $array2, "key_compare_func");  print_r($result);

Results:

string(1) "b"string(1) "a"=====1string(1) "b"string(1) "c"=====2int(0)string(1) "b"=====3string(1) "a"int(0)=====4int(0)string(1) "a"=====5int(1)int(0)=====6string(1) "a"int(0)=====7string(1) "a"string(1) "a"=====8int(0)string(1) "a"=====8int(0)int(0)=====9string(1) "b"string(1) "a"=====9string(1) "b"int(0)=====10string(1) "b"int(1)=====11string(1) "c"string(1) "a"=====12string(1) "c"int(0)=====13string(1) "c"int(1)=====14Array(    [b] => brown    [c] => blue    [0] => red)

Excuse me:

对于这个函数,他的比较原理是什么?为什么要进行14次比较?

Check the source code, before the comparison, PHP also carried out a sort operation, sorting will also take the callback function, which is what you will see in the results b and c the two appear in the same array of keys to compare the records.

  • 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.