<?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);
preferences:
44.7 ms | 402 KiB | 5 Q