This article introduces you to the content of PHP how to achieve a count of the code, there is a certain reference value, the need for friends can refer to, I hope to help you.
/** * Count Sort: a sort of bucket */$arr = [5,69,4,32,14,8,74,95,23,56,41,5,31,63];//include ' data.php '; $length = count ($arr); $ MaxValue = $arr [0];//finds the maximum value in the array for ($i =1; $i < $length; $i + +) { if ($arr [$i] > $maxValue) { $maxValue = $arr [$i]; }} /** * Fixed-length array, the key will be automatically sorted, PHP array is the implementation of the hash table, * if there is a normal array, the keys will not be automatically sorted, the nonexistent key will not automatically fill the null */$frequency = new Splfixedarray ($maxValue + 1 );/** * Statistics in arr, frequency */for ($i =0; $i < $length; $i + +) { if (empty ($frequency [$arr [$i]]) $frequency [$arr [$i ] ] = 0; $frequency [$arr [$i]] + = 1;} Empty $arr$arr = [];//traversal frequency, if its element has a value, then push the key to arr for ($i =0; $i < count ($frequency); $i + +) { if (!empty ($fre quency[$i]) {for ($j =0; $j < $frequency [$i]; $j + +) { $arr [] = $i; }} } Print_r ($arr);