Elementary Introduction to PHP source code 17: About ARRAY_DIFF,ARRAY_UDIFF,ARRAY_DIFF_UKEY,ARRAY_DIFF_UASSOC,ARRAY_UDIFF_UASSOC

Source: Internet
Author: User
Tags php source code
This article mainly introduces the introduction of PHP source code 17: About ARRAY_DIFF,ARRAY_UDIFF,ARRAY_DIFF_UKEY,ARRAY_DIFF_UASSOC,ARRAY_UDIFF_UASSOC, Have a certain reference value, now share to everyone, the need for friends can refer to

Elementary Introduction to PHP source code 17: About ARRAY_DIFF,ARRAY_UDIFF,ARRAY_DIFF_UKEY,ARRAY_DIFF_UASSOC,ARRAY_UDIFF_UASSOC

These 4 function calls are the same function Php_array_diff, the difference is their parameters.
Although all five functions call the same method, in this method, there is not too much common use of the program except for the manipulation of the input and the release of the associated memory.
Is it because of the similarity in semantics?

Array_diff:        Php_array_diff (Internal_function_param_passthru, Diff_normal,                                    diff_comp_data_internal, DIFF_ comp_key_internal); Array_diff_ukey:php_array_diff (Internal_function_param_passthru, Diff_key,                                 diff_comp_data_internal, DIFF_ Comp_key_user); Array_udiff:    Php_array_diff (Internal_function_param_passthru, Diff_normal,                            Diff_comp_data_user, DIFF_ comp_key_internal); Farray_diff_uassoc:php_array_diff (Internal_function_param_passthru, DIFF_ASSOC,                            DIFF_ Comp_data_internal, Diff_comp_key_user); Array_udiff_uassoc:php_array_diff (Internal_function_param_passthru, Diff_assoc,                            DIFF_COMP_DATA_USER, DIFF_ Comp_key_user);

Program Description:

After the input has been obtained and related error handling has been made
The program first confirms what the comparison function is, here, there are different comparison functions for different behavior and data_compare_type, and there are different input parameter error handling
The input parameters are then copied and sorted according to the previously obtained Diff_key_compare_func, and the sort call is the Zend_qsort function
Then initialize the hash table that returns the array and copy the first argument to the returned array
Finally, it iterates through all the values of the first parameter and determines if it is not in another parameter.
During traversal, if a value in another parameter deletes all elements in the returned array that are equal to this value, if one of the values is not in another parameter, skip
This leaves the value that needs to be returned.

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.