Solve the problem encountered when using the PHP function array_udiff

Source: Internet
Author: User
This article describes how to solve the problems encountered in the use of the PHP function array_udiff, which has some reference value. let's take a look at it. Solve the problem encountered when using the PHP function array_udiff

 Code = intval ($ code);} public function getCode () {return $ this-> code;}/*** this function must return 0, 1, -1 values can be used to calculate the travel set */public static function cmp ($ a, $ B) {if ($ a-> getCode () ===$ B-> getCode () return 0; return $ a-> getCode ()> $ B-> getCode ()? 1:-1;}/*** this form is written in the book "in-depth PHP object-oriented mode and practice". * It is verified to be invalid, in chapter 10, I will explain the combination mode */public static function cmp2 ($ a, $ B) {return $ a ===$ B? 0: 1 ;}}$ e1 = new Obj ('20140901'); $ e2 = new Obj ('20140901'); $ e3 = new Obj ('20140901 '); $ e4 = new Obj ('000000'); $ e5 = new Obj ('000000'); $ e6 = new Obj ('000000'); $ arr = [$ e1, $ e2, $ e3, $ e4, $ e5, $ e6]; $ arr2 = [$ e2, $ e3, $ e6]; $ arr = array_udiff ($ arr, $ arr2, ['obj ', 'cmp']); // $ arr = array_udiff ($ arr, $ arr2, ['obj ', 'cmp2']); // The comparison method cmp2 cannot return the correct result var_dump ($ arr );

Note:

1. The return result is a difference set, and the key name remains unchanged.

2. the two units are only in(String) $ elem1 ===( string) $ elem2Is considered the same. That is to say, when the expression of the string is the same.

Similar functions:

array_diff_assocarray_diff_uassocarray_diff_keyarray_diff_ukeyarray_udiff_assocarray_udiff_uassoc

Summary:

Array_diff and array_udiff are determined only by value.

Array_diff_key and array_diff_ukey are only determined based on the key.

Array_diff_assoc, array_diff_uassoc, array_udiff_assoc, and array_udiff_uassoc are determined by key and value together.

The above is the details about how to solve the problem encountered in the use of the PHP function array_udiff. For more information, see other related articles in the first PHP community!

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.