3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['user_id' => 82, 'ac_type' => 1, 'irrelevant' => 'a'], ['user_id' => 80, 'ac_type' => 5, 'irrelevant' => 'b'], ['user_id' => 76, 'ac_type' => 1, 'irrelevant' => 'c'], ['user_id' => 82, 'ac_type' => 1, 'irrelevant' => 'd'], ['user_id' => 80, 'ac_type' => 5, 'irrelevant' => 'e'] ]; foreach ($array as $row) { $compositeKey = $row['user_id'] . '_' . $row['ac_type']; $result[$compositeKey] ??= $row; // only store if first occurrence of compositeKey } var_export(array_values($result)); // re-index and print
Output for 8.0.1 - 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
array ( 0 => array ( 'user_id' => 82, 'ac_type' => 1, 'irrelevant' => 'a', ), 1 => array ( 'user_id' => 80, 'ac_type' => 5, 'irrelevant' => 'b', ), 2 => array ( 'user_id' => 76, 'ac_type' => 1, 'irrelevant' => 'c', ), )

preferences:
91.57 ms | 407 KiB | 5 Q