array_udiff包含对象,我做错了什么?

时间:2015-03-20 10:31:15

标签: php arrays object

我有两个带有3个成员的stdClass对象的数组。数组$deselectedIds的所有成员都是数组$ids中的成员,但具有不同的键。我希望它们从数组$ids中删除。试过这个,没有成功:

$result = array_udiff($ids, $deselectedIds, function($a, $b) {
            return ($a->contactId == $b->contactId) && ($a->addressId == $b->addressId) && ($a->customerId == $b->customerId) ? 0 : 1;
        });
var_dump(count($result)) returns the same as var_dump(count($ids))

示例数据:

$deselectedIds = array(
        "97830-90473-90253" => (object)array(
            "contactId" => "97830",
            "addressId" => "90473",
            "customerId" => "90253",
        ),
        "165837-146683-144677" => (object)array(
            "contactId" => "165837",
            "addressId" => "146683",
            "customerId" => "144677",
        ),
        "133004-119729-118853" => (object)array(
            "contactId" => "133004",
            "addressId" => "119729",
            "customerId" => "118853",
        ),
        "174081-153779-151573" => (object)array(
            "contactId" => "174081",
            "addressId" => "153779",
            "customerId" => "151573",
        )
    );


$ids = array(
        (object)array(
            "contactId" => 97830,
            "addressId" => 90473,
            "customerId" => 90253,
        ),
        (object)array(
            "contactId" => 213424,
            "addressId" => 23423,
            "customerId" => 234234,
        ),
        (object)array(
            "contactId" => 57675,
            "addressId" => 756765,
            "customerId" => 57567,
        ),
        (object)array(
            "contactId" => 165837,
            "addressId" => 146683,
            "customerId" => 144677,
        ),
        (object)array(
            "contactId" => 231567,
            "addressId" => 23453,
            "customerId" => 3453453,
        ),
        (object)array(
            "contactId" => 133004,
            "addressId" => 119729,
            "customerId" => 118853,
        ),
        (object)array(
            "contactId" => 174081,
            "addressId" => 153779,
            "customerId" => 151573,
        )
    );

任何想法我做错了什么?

0 个答案:

没有答案