3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function doopScooper($dataArray, $uniqueKeys){ foreach($dataArray as $row){ $checkArray = []; foreach($uniqueKeys as $key) $checkArray[$key] = isset($row[$key]) ? $row[$key] : NULL; $checkArrayString = json_encode($checkArray); $matchcount = 0; foreach($dataArray as $id=>$array){ $currentArray = []; foreach($uniqueKeys as $key) $currentArray[$key] = isset($array[$key]) ? $array[$key] : NULL; $currentArrayString = json_encode($currentArray); if($currentArrayString == $checkArrayString) $matchcount++; if($matchcount > 1) unset($dataArray[$id]); } } return $dataArray; } $dataArray = array( array("id"=>0, "fname"=>"Robert", "lname"=>"Pamblam", "address"=>"1231 main st"), array("id"=>1, "fname"=>"Robert", "lname"=>"Pamblam", "address"=>"1232 main st"), array("id"=>2, "fname"=>"Roberto", "lname"=>"Pamblam", "address"=>"1233 main st"), array("id"=>3, "fname"=>"Roberta", "lname"=>"Pamblam", "address"=>"1234 main st"), array("id"=>4, "fname"=>"Roberta", "lname"=>"Pamblam", "address"=>"1235 main st"), array("id"=>5, "fname"=>"Robert", "lname"=>"Pamblamo", "address"=>"1236 main st"), array("id"=>6, "fname"=>"Robert", "lname"=>"Pamblamo", "address"=>"1237 main st") ); $uniqueKeys = array('fname', 'lname'); $newarray = doopScooper($dataArray, $uniqueKeys); var_dump($newarray); exit;
based on WUVbI
Output for 5.4.0 - 7.2.0
array(1) { [0]=> array(4) { ["id"]=> int(0) ["fname"]=> string(6) "Robert" ["lname"]=> string(7) "Pamblam" ["address"]=> string(12) "1231 main st" } }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/RZRRZ on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/RZRRZ on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/RZRRZ on line 5
Process exited with code 255.