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] => ) Link to comment https://forums.phpfreaks.com/topic/109002-help-with-combining-array-values/ 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? Link to comment https://forums.phpfreaks.com/topic/109002-help-with-combining-array-values/#findComment-559179 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 Link to comment https://forums.phpfreaks.com/topic/109002-help-with-combining-array-values/#findComment-559181 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. Link to comment https://forums.phpfreaks.com/topic/109002-help-with-combining-array-values/#findComment-559183 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 Link to comment https://forums.phpfreaks.com/topic/109002-help-with-combining-array-values/#findComment-559187 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.