Hello to all! It is necessary to make the TOP-10 of the most repetitive words (more than 3 letters) from the file input.txt and put them in the outbox.txt file after sorting.

The input.txt file contains the words line by line.

I started to do it, but I cannot do the sorting.

Here is my beginning:

$f_arr = file( "input.txt" ); $new = 0; for ($i = 0; $i < sizeof($f_arr); $i++) { if(strlen($f_arr[$i])-2 > 3) { $arr[$new] = $f_arr[$i]; $new = $new +1; } } //сортировка foreach($arr as $a) { echo $a . '<br />'; } 

Thank you in advance.

    1 answer 1

     if(strlen($f_arr[$i])-2 > 3) { $arr[$f_arr[$i]] = ($arr[$f_arr[$i]] > 0) ? $arr[$f_arr[$i]]+1 : 1; } 

    then sort by value.

    mb even like this:

     if(strlen($f_arr[$i])-2 > 3) { $arr[$f_arr[$i]]++; } 
    • It is not clear how it works. If it's not difficult for you, you could connect with my code, for I got lost. =) - Chosen
    • In fact, a key is written into an associative array — a word, and the value of the key is added to 1. Then you sort in descending order by value and output data through foreach. Something like this. Let's pick up the code yourself, there crtl + c ctrl + v only use. - lampa