binujayaraj Posted July 23, 2008 Share Posted July 23, 2008 I do have an array with me. $arr = array( 10, 11, 12, 13, 14, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 20, 21, 22, 23, 24 ); could any one provide me an optimized code to return unique values from repeating elements. output of the code should be array(15, 24) any help ? Thanks, Binu Jayaraj Link to comment https://forums.phpfreaks.com/topic/116267-solved-unique-value-from-repeating-elements/ Share on other sites More sharing options...
DarkWater Posted July 23, 2008 Share Posted July 23, 2008 Wait. You only want elements that don't show up more than once? Link to comment https://forums.phpfreaks.com/topic/116267-solved-unique-value-from-repeating-elements/#findComment-597837 Share on other sites More sharing options...
binujayaraj Posted July 23, 2008 Author Share Posted July 23, 2008 yes that's correct. plz help !! Link to comment https://forums.phpfreaks.com/topic/116267-solved-unique-value-from-repeating-elements/#findComment-597845 Share on other sites More sharing options...
DarkWater Posted July 23, 2008 Share Posted July 23, 2008 <?php $arr = array( 10, 11, 12, 13, 14, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 20, 21, 22, 23, 24 ); $count = array_count_values($arr); foreach ($count as $k=>$v) { if ($v === 1) { $unique[] = $k; } } ?> Link to comment https://forums.phpfreaks.com/topic/116267-solved-unique-value-from-repeating-elements/#findComment-597848 Share on other sites More sharing options...
binujayaraj Posted July 23, 2008 Author Share Posted July 23, 2008 The code works absolutely as desired. Thanks a lot gentleman. Link to comment https://forums.phpfreaks.com/topic/116267-solved-unique-value-from-repeating-elements/#findComment-597858 Share on other sites More sharing options...
DarkWater Posted July 23, 2008 Share Posted July 23, 2008 No problem. Please mark this topic as "Solved" by clicking the appropriate button in the bottom-left corner of the thread. Link to comment https://forums.phpfreaks.com/topic/116267-solved-unique-value-from-repeating-elements/#findComment-597866 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.