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.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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:
148.98 ms | 403 KiB | 121 Q