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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -