This article mainly introduces the sort, asort, and ksort usage of PHP array sorting. The example briefly demonstrates the usage of sort, asort, and ksort, and provides annotations to describe them in detail, for more information about how to use sort, asort, and ksort in PHP array sorting. The specific example is as follows:
<? Php $ arr = array ('D' => 'sdf ', 'R' => 'sdf', 'a' => 'Eee '); // sort ($ arr); // sorts the values of the array, deletes the previous key value, and changes it to the index array // asort ($ arr ); // sorts the array by value and maintains the index relationship. ksort ($ arr) applies to the index array and associated array; // sorts the array by key value, and maintain the index relationship, both the index array and the associated array are applicable // The corresponding reverse order and rsort arsort krsort // compare the usort uksort uasort. The second parameter is the comparison function. The first parameter must be equal to or greater than the second parameter. return a floating point number equal to or greater than 0. only the integer part print_r ($ arr);?>
The examples in this article only demonstrate the usage of ksort. if you are interested, you can test the running results of sort and asort to gain a better understanding of them. I hope this example will help you with PHP programming.