Before you go all duplicate of "question" on me. Please read out the situation.
In my application I build objects based on data from the database. However sometimes I happens that the same database entry is read twice due to a LIKE
statement in my sql query(which runs once for each user in the group of the current user). Due to this it can happen that multiple equal objects are created which will not be considered duplicates according to array_unique
.
//These objects are equal but are not duplicates.
//And these cases need to be removed from the array.
$z = new Obj(1,2,3);
$y = new Obj(1,2,3);
//code example
$e = array();
while($row = mysqli_fetch_array($result)){ //result is result from query.
$a = $row['var1']; //obtains data from result
$b = $row['var2'];
$c = $row['var3'];
$d = new Obj($a, $b, $c); //Creates new object
array_push($e, $d); //Holds all objects
}
class Obj{
public $a;
public $b;
public $c;
public function __construct($a, $b, $c){
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
}
//This could work but it is a slow(forbidden) algorithm.
foreach($e as $f){
foreach($e as $g){
//REMOVE DUPLICATES
}
}
//This wont work because technically the 2 duplicates are 2 different objects.
//And not duplicates right?
$e = array_unique($e)
So the question is: Is there a simple or faster way to remove any duplicates from this array instead of using a double loop?