3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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);
based on JI5OK
Output for 5.0.0 - 5.6.21, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
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.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" } }