Created
September 10, 2016 21:11
-
-
Save nickabal/3c091446566d96d3619fd8b67ea9ac47 to your computer and use it in GitHub Desktop.
given string of book count the words using php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$book = 'Some Text Is Here Text Is Text Text characters'; | |
$book_words = explode(" ", $book); | |
$counted_words = array(); | |
foreach ( $book_words as $word ) { | |
if ( array_key_exists($word, $counted_words) ) { | |
$counted_words[$word]++; | |
} else { | |
$counted_words[$word] = 1; | |
} | |
} | |
foreach ( $counted_words as $word => $count ) { | |
echo $word. " : ". $count. "<br>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment