3v4l.org

run code in 300+ PHP versions simultaneously
<?php function unique_multidim_array($array, $key) { $uniq = []; foreach($array as $val) { $curVal = $val[$key]; // shortcut of the value $uniq[$curVal] = $val; // override previous value if exists } return array_values($uniq); // array_values to re-index array } $exists = [ ['intervention_id' => 2, 'exists' => 'yes'], ['intervention_id' => 2, 'exists' => 'no'], ['intervention_id' => 2, 'exists' => 'yes'], ['intervention_id' => 5, 'exists' => 'yes'], ['intervention_id' => 6, 'exists' => 'no'], ['intervention_id' => 12, 'exists' => 'yes'], ]; $uniq = unique_multidim_array($exists, 'intervention_id'); print_r($uniq);
Output for 7.4.0 - 7.4.30, 8.0.1 - 8.0.20, 8.1.0 - 8.1.7
Array ( [0] => Array ( [intervention_id] => 2 [exists] => yes ) [1] => Array ( [intervention_id] => 5 [exists] => yes ) [2] => Array ( [intervention_id] => 6 [exists] => no ) [3] => Array ( [intervention_id] => 12 [exists] => yes ) )

preferences:
34.97 ms | 410 KiB | 5 Q