Solution
1. read data from the congtent field of the database and combine them into a string.
Copy codeThe Code is as follows:
<? Php
While ($ myrow = $ connector-> fetch_array ($ result ))
{
// $ R [] = explode (",", $ myrow ["content"]);
$ Str. = $ myrow ["content"]. ',';
}
$ Arr_str = substr ($ str, 0,-1 );
?>
Because the last number is followed by a comma, you must intercept the string.
2. Split the string into arrays by commas.
Copy codeThe Code is as follows:
$ R = explode (",", $ arr_str );
3. Use array_count_values () to calculate the number of elements in a one-dimensional array.
Because array_count_values () does not seem to be able to directly count the number of elements in a two-dimensional array, we have performed the preceding two steps to obtain a one-dimensional array.
The array_count_values () function is used to count the number of occurrences of all values in the array. Returns an array. The key name of the element is the value of the original array, and the key value is the number of times this value appears in the original array.
Copy codeThe Code is as follows:
$ Rs = array_count_values ($ r );
4. Sorting
Copy codeThe Code is as follows:
Asort ($ rs );
Echo '<pre> ';
Print_r ($ rs );
Echo '</pre> ';