How to count the unique words in a string with PHP

1 Answer

0 votes
$str = 'python javascript c cpp php cpp php java javascript python';
 
echo count(array_unique(str_word_count($str, 1))) . "\n";


 
 
 
/*
run:
   
6
   
*/

 



answered May 3, 2022 by avibootz

Related questions

1 answer 214 views
1 answer 169 views
1 answer 179 views
1 answer 210 views
1 answer 199 views
1 answer 204 views
1 answer 211 views
...