Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 检查对象数组php laravel中的重复条目_Arrays_Laravel_Duplicates - Fatal编程技术网

Arrays 检查对象数组php laravel中的重复条目

Arrays 检查对象数组php laravel中的重复条目,arrays,laravel,duplicates,Arrays,Laravel,Duplicates,标识两个对象数组具有相同的密码\u代码返回布尔值如果存在true else false已尝试数组\u计数\u值仅返回字符串和数字请指导谢谢 我只想检查数组中是否检测到相同的密码给我true else false可能的重复项不是重复项我只想检查数组中是否检测到相同的密码给我true else false收集的是什么。。?表示undefinedcollect是一个从数组创建集合的函数:Bdw我使用的是4.2。这不起作用,希望您理解我的问题,如果$users[0]['secret\u code']与$

标识两个对象数组具有相同的密码\u代码返回布尔值如果存在true else false已尝试数组\u计数\u值仅返回字符串和数字请指导谢谢


我只想检查数组中是否检测到相同的密码给我true else false

可能的重复项不是重复项我只想检查数组中是否检测到相同的密码给我true else false收集的是什么。。?表示undefinedcollect是一个从数组创建集合的函数:Bdw我使用的是4.2。这不起作用,希望您理解我的问题,如果$users[0]['secret\u code']与$users[1]['secret\u code']完全匹配,则应返回true,否则返回truefalse@Ross您在使用v4.2之前应该提到,这样,你做的工作太少,而试图回答你的人不得不做太多的猜测。
Illuminate\Database\Eloquent\Collection Object
(
    [items:protected] => Array
        (
            [0] => User Object
                (
                    [original:protected] => Array
                        (
                            [user_id] => 123456
                            [active] => 1
                            [name] => ABC XYZ
                            [first_name] => ABC
                            [last_name] => XYZ
                            [email] => abc@xyz.com
                            [username] => abcxyz
                            [secret_code] => S4#$sdD                           
                        )
                )

            [1] => User Object
                (

                    [original:protected] => Array
                        (
                            [user_id] => 987654
                            [active] => 1
                            [name] => CBD IHK
                            [first_name] => CBD
                            [last_name] => IHK
                            [email] => abc@xyz.com
                            [username] => seCdils
                            [secret_code] => S4#$sdD
                        )

                )

        )

)
<?php

$dupes = []; // keep track of duplicates
foreach ($users as $user1) { // iterate over all items
    $dupeCount = 0; // because we iterate over the same array, we always find at least the item itself (1 dupe minimum)

    foreach ($users as $user2) { // check the array again
        if ($user1 === $user2) { // if they are exactly the same: http://php.net/manual/en/language.oop5.object-comparison.php
            $dupeCount++;
        }
        if ($dupeCount > 1) { // because we always find at least 1, push only when we find more than that
            array_push($dupes, $user1); // add it to the result
        }
    }
}
collect($users)->unique(function ($item) {
    return $item['secret_code'];
});