3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array ('1' => (object)array( 'id' => 225, 'user_id' => 1, 'name' => 'Blue Quilted Leather Jacket by Minusey - $499' ), '2' => (object)array( 'id' => 222, 'user_id' => 1, 'name' => 'Darling New Bathtub by Duravit - $6300' ), '3' => (object)array( 'id' => 222, 'user_id' => 1, 'name' => 'Darling New Bathtub by Duravit - $6300' ) ); //print_r(array_column((array)$array, 'id')); $arr_new = array(); $arr_temp_ids = array(); foreach($array as $key=>$arr_obj) { $arr_val = get_object_vars($arr_obj); if(!isset($arr_temp_ids[$arr_val['id']])) { $arr_new[] = $arr_obj; $arr_temp_ids[$arr_val['id']] = true; } } var_dump($arr_new);
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.21, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(2) { [0]=> object(stdClass)#1 (3) { ["id"]=> int(225) ["user_id"]=> int(1) ["name"]=> string(45) "Blue Quilted Leather Jacket by Minusey - $499" } [1]=> object(stdClass)#2 (3) { ["id"]=> int(222) ["user_id"]=> int(1) ["name"]=> string(38) "Darling New Bathtub by Duravit - $6300" } }
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9
array(2) { [0]=> object(stdClass)(3) { ["id"]=> int(225) ["user_id"]=> int(1) ["name"]=> string(45) "Blue Quilted Leather Jacket by Minusey - $499" } [1]=> object(stdClass)(3) { ["id"]=> int(222) ["user_id"]=> int(1) ["name"]=> string(38) "Darling New Bathtub by Duravit - $6300" } }

preferences:
297.85 ms | 402 KiB | 356 Q