kaveman50 Posted October 22, 2009 Share Posted October 22, 2009 Hello guys. Does anyone know how to input a sentence, and then output how many of each character was used in the sentence? My sentence will be, "The green fox jumped over the yellow lion." Link to comment https://forums.phpfreaks.com/topic/178665-array-help/ Share on other sites More sharing options...
Mark Baker Posted October 22, 2009 Share Posted October 22, 2009 $sentence = "The green fox jumped over the yellow lion."; $sentenceArray = str_split($sentence); print_r(array_count_values($sentenceArray)); Link to comment https://forums.phpfreaks.com/topic/178665-array-help/#findComment-942433 Share on other sites More sharing options...
kaveman50 Posted October 24, 2009 Author Share Posted October 24, 2009 Thanks Mark. By any chance, do you know how to output the A's as just one array? (Instead of displaying the upper and lowercase separately.) Link to comment https://forums.phpfreaks.com/topic/178665-array-help/#findComment-943640 Share on other sites More sharing options...
Alex Posted October 24, 2009 Share Posted October 24, 2009 Use strtolower() to convert the string to all lower-case before array_split(). eg $setenceArray = str_split(strtolower($sentence)); Link to comment https://forums.phpfreaks.com/topic/178665-array-help/#findComment-943649 Share on other sites More sharing options...
kaveman50 Posted October 25, 2009 Author Share Posted October 25, 2009 Thanks Alex Link to comment https://forums.phpfreaks.com/topic/178665-array-help/#findComment-943763 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.