3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function doopScooper($dataArray, $uniqueKeys){ foreach($dataArray as $k=>$row){ $checkArray = []; foreach($uniqueKeys as $key){ $checkArray[$key] = isset($row[$key]) ? $row[$key] : NULL; } var_dump($checkArray); exit; } } $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;
Output for 5.4.0 - 7.2.0
array(2) { ["fname"]=> string(6) "Robert" ["lname"]=> string(7) "Pamblam" }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/WUVbI 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/WUVbI on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/WUVbI on line 5
Process exited with code 255.