perezf Posted June 6, 2008 Share Posted June 6, 2008 i have an array that has a few of the same values I just want it to combine all the same values how can i do that Array ( [0] => 10 [1] => 16 [2] => 17 [3] => 10 [4] => 11 [5] => 12 [6] => ) Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 6, 2008 Share Posted June 6, 2008 What do you mean by combine the same values, do you mean added together? Or just all occurrences removed but 1? Quote Link to comment Share on other sites More sharing options...
perezf Posted June 6, 2008 Author Share Posted June 6, 2008 I just want to remove the duplicates Quote Link to comment Share on other sites More sharing options...
RMcLeod Posted June 6, 2008 Share Posted June 6, 2008 if you mean remove duplicate values use array_unique <?php $old_array = array(10, 16, 17, 10, 11, 12); print_r($old_array); $new_array = array_unique($old_array); print_r($new_array); ?> returns Array ( [0] => 10 [1] => 16 [2] => 17 [3] => 10 [4] => 11 [5] => 12 ) Array ( [0] => 10 [1] => 16 [2] => 17 [3] => 11 [4] => 12 ) One thing to note is that this will only work of duplicate value === duplicate value e.g. an array containing 10 and '10' will see these as different values as one is an integer and the other is a string. Quote Link to comment Share on other sites More sharing options...
perezf Posted June 6, 2008 Author Share Posted June 6, 2008 and one of my array values are blank how can i remove those 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.