e.g. "I think I got a long way to go to market."
In this case, I want to output
I 2
think 1
got 1
a 1
long 1
way 1
to 2
go 1
market 1
Code:
<?php
$tmp = explode (" ", $text);
echo "
My Words
Repetition
";
foreach ($tmp as $a)
{
echo "" $a."" ;
echo "" ;
}
echo ""
?>
ADyson
62.9k16 gold badges90 silver badges100 bronze badges
-
1Does this answer your question? PHP - count specific array valuesmighty_dev– mighty_dev2022年10月26日 08:38:47 +00:00Commented Oct 26, 2022 at 8:38
1 Answer 1
You can try with
$text = "I think I got a long way to go to market.";
$tmp = explode (" ", $text);
foreach($tmp as $a){
$result[$a] += 1;
}
foreach($result as $value => $occurrences){
echo "$value $occurrences\n";
}
Sign up to request clarification or add additional context in comments.
Comments
lang-php