PHP array sorting sort, asort and ksort usage, asortksort. PHP array sorting sort, asort and ksort usage. asortksort shares the sort, asort, and ksort usage of PHP array sorting. The example demonstrates the sort, asort, and ksort usage, PHP array sorting sort, asort and ksort usage, and asortksort
Share the sort, asort, and ksort usage of PHP array sorting. The example shows the usage of sort, asort, and ksort, and provides annotations to describe them in detail.
The usage of sort, asort, and ksort in PHP array sorting.
'Sdf ', 'R' => 'sdf', 'a' => 'Eee '); // sort ($ arr); // sorts the array values, delete the previous key value to the index array // asort ($ arr); // sort the array by value and maintain the index relationship, ksort ($ arr) is applicable to index arrays and associated arrays; // sorts arrays by key value and maintains 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 is obtained. // www. jbxue. comprint_r ($ arr);?>
The examples in this article only demonstrate the usage of ksort. you can test the running results of sort and asort to gain a deeper understanding and grasp it.
Php uses the asort and ksort functions to sort array elements.
I don't know how you wrote it. it's missing planet1, but you don't need it. you can just use this 2. In addition, use commas (,) to separate the array blocks, instead of semicolons, use a semicolon to end the statement. below is my change. let's see for yourself ..
$ Planet2 = array (
'X' => 'global ',
'Y' => 'Venus ',
'Z' => 'Mars ',
'A' => 'Jupiter ',
'B' => 'Saturn ',
);
Asort ($ planet2 );
Echo 'use the function asort to sort array elements :';
Echo' ';
Foreach ($ planet2 as $ key => $ value)
{
Echo 'planet2 ['. $ key.'] = '. $ value;
Echo' ';
Echo' ';
}
Echo' ';
Echo 'use the ksort function to sort array elements :';
Echo' ';
Ksort ($ planet2 );
Foreach ($ planet2 as $ key => $ value)
{
Echo 'planet2 ['. $ key.'] = '. $ value;
Echo' ';
Echo' ';
}
?>
Php reverse and forward
In fact, it is helpful to look at the php Manual. what is the forward and reverse directions used by LZ? Use the following command directly on the array:
Sort the array by key name: ksort ($ array)
Sort the array in reverse order by key name: krsort ($ array)
Sort the array and maintain the index relationship: asort ($ array)
Sort the array in reverse order and maintain the index relationship: arsort ($ array)
Reverse sorting of arrays: rsort
Sort arrays: sort
Tips: I will share the sort, asort, and ksort usage of PHP array sorting. The example demonstrates the usage of sort, asort, and ksort, and provides annotations...