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) Link to comment https://forums.phpfreaks.com/topic/79802-solved-array-or-string-search/ 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 Link to comment https://forums.phpfreaks.com/topic/79802-solved-array-or-string-search/#findComment-404094 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); Link to comment https://forums.phpfreaks.com/topic/79802-solved-array-or-string-search/#findComment-404095 Share on other sites More sharing options...
asmith Posted December 2, 2007 Author Share Posted December 2, 2007 thanks guys ! really helped ! Link to comment https://forums.phpfreaks.com/topic/79802-solved-array-or-string-search/#findComment-404099 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.