<?php
$array = [
['user_id' => 82, 'ac_type' => 1],
['user_id' => 80, 'ac_type' => 5],
['user_id' => 76, 'ac_type' => 1],
['user_id' => 82, 'ac_type' => 2],
['user_id' => 80, 'ac_type' => 5]
];
foreach ($array as $a) {
if (!isset($result[$a['user_id']])) {
$result[$a['user_id']] = $a; // only store if first occurrence of user_id
}
}
var_export(array_values($result)); // re-index and print
- 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 (
'user_id' => 82,
'ac_type' => 1,
),
1 =>
array (
'user_id' => 80,
'ac_type' => 5,
),
2 =>
array (
'user_id' => 76,
'ac_type' => 1,
),
)
preferences:
103.21 ms | 402 KiB | 121 Q