Removing duplicate entries in an array- Undefined offset error(PHP) -
i new php , trying remove duplicate entries in array. end desired output, getting 2 "undefined offset" errors along way. code have: $this->master refers array declared in beginning of class.
public function removeduplicates(){ $var = count($this->master); for($i = 0; $i < $var; $i++){ for($j = 0; $j <$var; $j++){ if(($this->master[$i] == $this->master[$j]) && $i != $j){ $this->shiftleft($j, $var); $var --; } } } } public function shiftleft($t, $s){ while($t < $s){ echo "$t "; $this->master[$t] = $this->master[$t+1]; $t++; } unset($this->master[$t-1]); }
it simple logical error cannot seem find where. appreciated.
see if works
$unique = array_unique($this->master);