3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ 0 => [ "SERIAL" => "qwerty", "BRANCH" => "TEST1" ], 1 => [ "SERIAL" => "qwer", "BRANCH" => "TEST1" ], 2 => [ // RETURN THIS AS ERROR AS THE BRANCH "TEST1" has already "qwerty" serial "SERIAL" => "qwerty", "BRANCH" => "TEST2" ], 3 => [ "SERIAL" => "qwerty", "BRANCH" => "TEST1" ], 4 => [ // RETURN THIS AS ERROR AS THE BRANCH "TEST1" has already "qwerty" serial "SERIAL" => "qwerty", "BRANCH" => "TEST3" ], ]; foreach($arr as $sub){ $result[$sub['SERIAL']][] = $sub['BRANCH']; } foreach($result as $branches){ $unique = array_unique($branches); if(count($unique) >1){ var_dump("ERROR:", array_slice($unique,1)); } }
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
string(6) "ERROR:" array(2) { [0]=> string(5) "TEST2" [1]=> string(5) "TEST3" }

preferences:
154.63 ms | 408 KiB | 5 Q