1

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
asked Oct 26, 2022 at 8:30
1

1 Answer 1

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";
}
answered Oct 26, 2022 at 8:46
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.