MOORTHY Posted on Nov 3, 2020 How do I find most used 10 words in php #php #webdev #javascript Anyone help me how do I find most used 10 words in php Top comments (3) Subscribe Submit Preview Dismiss Collapse Expand Lawrence Lagerlof Lawrence Lagerlof Lawrence Lagerlof Follow Avid Isaac Asimov reader. Backend and frontend developer. Education Bachelor of Science in Information Technology Joined Aug 22, 2018 • Nov 3 '20 • Edited on Nov 3 • Edited Dropdown menu Copy link Hide <?php $arr = ['a', 'b', 'a', 'c', 'd', 'd', 'd']; /* Or this, if your input is a string $arr = explode(' ', 'a b a c d d d'); */ $arr_count = []; foreach ($arr as $v) { $arr_count[$v] = isset($arr_count[$v]) ? $arr_count[$v] + 1 : 1; } arsort($arr_count); print_r($arr_count); Enter fullscreen mode Exit fullscreen mode Collapse Expand Lawrence Lagerlof Lawrence Lagerlof Lawrence Lagerlof Follow Avid Isaac Asimov reader. Backend and frontend developer. Education Bachelor of Science in Information Technology Joined Aug 22, 2018 • Nov 3 '20 Dropdown menu Copy link Hide Put the tag #help in this question, please. Collapse Expand David David David Follow 401 profile not authorized Joined Jul 3, 2020 • Nov 3 '20 • Edited on Nov 3 • Edited Dropdown menu Copy link Hide You could split the words based on spaces and count how many times each word is mentioned and get the top 10 words like that. Code of Conduct • Report abuse
Top comments (3)
Put the tag #help in this question, please.
You could split the words based on spaces and count how many times each word is mentioned and get the top 10 words like that.