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 Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
binujayaraj Posted July 23, 2008 Author Share Posted July 23, 2008 yes that's correct. plz help !! Quote Link to comment 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; } } ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.