my goal is to find duplicates in an array of objects, but only for specific object-variables.
Instead of using two foreach-loops like the following, I am searching for a better (more elegant) way to find the duplicates:
foreach ($data as $date) {
foreach ($data as $innerDate) {
if ($date->birthday == $innerDate->birthday &&
$date->street == $innerDate->street &&
$date->streetnr == $innerDate->streetnr &&
$date->zipcode == $innerDate->zipcode &&
$date->twinid == $innerDate->twinid &&
$date !== $innerDate) {
// Duple
}
}
}
Thanks!
Now, I'm using following code, based on Tarilo's idea:
usort($data, function($obj_a, $obj_b){
if ($obj_a->birthday == $obj_b->birthday &&
$obj_a->street == $obj_b->street &&
$obj_a->streetnr == $obj_b->streetnr &&
$obj_a->zipcode == $obj_b->zipcode &&
$obj_a->twinid == $obj_b->twinid) {
// Duple
}
});
Looks much better than two foreach-Loops ;-)