asmith Posted December 2, 2007 Share Posted December 2, 2007 how can i search a string or an array to find out how many a word or a value has been repeated ? for example : $a = array ("a","b","c","a","a","c","d"); $b = "a,b,b,b,c,c,a,a,a,d"; how can i find how many "a" are in those ? (actuallly with implode and explode , it will be one question) Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 2, 2007 Share Posted December 2, 2007 preg_match_all will do this quite easily. http://us2.php.net/manual/en/function.preg-match-all.php PhREEEK Quote Link to comment Share on other sites More sharing options...
lur Posted December 2, 2007 Share Posted December 2, 2007 http://php.net/array_count_values $a = array('a','b','c','a','a','c','d'); $b = array_count_values($a); echo $b['a']; // number of a's print_r($b); Quote Link to comment Share on other sites More sharing options...
asmith Posted December 2, 2007 Author Share Posted December 2, 2007 thanks guys ! really helped ! 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.