desadevil Posted July 21, 2008 Share Posted July 21, 2008 Hi, I'm new! Say I have an array, and I want to count how many times values appear, and how many types of values are there in the array, what should I do? e.g. $hello = array("4", "12", "12", "3", "3", "12", "3", "4", "4", "12", "3"); So in this array, there are 3 types of values, 4, 12, 3. What should I do to make the program know the number of types of values? Thank you!!! Link to comment https://forums.phpfreaks.com/topic/115893-solved-please-help~-counting-data-in-arrays/ Share on other sites More sharing options...
kenrbnsn Posted July 21, 2008 Share Posted July 21, 2008 You want to use the function array_count_values() <?php $hello = array("4", "12", "12", "3", "3", "12", "3", "4", "4", "12", "3"); $x = array_count_values($hello); echo '<pre>' . print_r($x,true) . '</pre>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/115893-solved-please-help~-counting-data-in-arrays/#findComment-595872 Share on other sites More sharing options...
desadevil Posted July 21, 2008 Author Share Posted July 21, 2008 Thank you!!! Link to comment https://forums.phpfreaks.com/topic/115893-solved-please-help~-counting-data-in-arrays/#findComment-595878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.