Finds the number of times each word occurs and save in php array -
i want create function countwords($str) takes string of characters , finds number of times each word occurs. exp:
"hello world"
character || number of times ouccr
h 1 e 1 l 3 o 2 w 1 r 1 d 1 help me !!
thanks....
try this:
<?php $str = 'hello world'; $str = str_replace(' ', '', $str); $arr = str_split($str); $rep = array_count_values($arr); foreach ($rep $key => $value) { echo $key . " = " . $value . '<br>'; } output:
h = 1 e = 1 l = 3 o = 2 w = 1 r = 1 d = 1
Comments
Post a Comment