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 138 views
1 answer 98 views
1 answer 102 views
1 answer 126 views
1 answer 115 views
1 answer 114 views
1 answer 119 views
...