PHP-Array sorting function
In this chapter, we will introduce the following PHP array sorting functions:
Sort ()-ascending order of arrays
Rsort ()-Descending order of the array
Asort ()-Sets the array in ascending order based on the values of the associative arrays
Ksort ()-an array is sorted in ascending order based on the keys of the associative arrays
Arsort ()-sorts arrays in descending order based on the values of the associative array
Krsort ()-Sorts the arrays in descending order based on the keys of the associative array
Sort ()-ascending order of arrays
The following instance arranges the elements in the $cars array in ascending alphabetical order:
Instance
<?php
$cars =array ("Volvo", "BMW", "Toyota");
Sort ($cars);
?>
The following instance arranges the elements in the $numbers array in ascending order of numbers:
Instance
<?php
$numbers =array (4,6,2,22,11);
Sort ($numbers);
?>
Rsort (www.bjrongjinhuiyin.com)-descending order of arrays
The following instance arranges the elements in the $cars array in descending alphabetical order:
Instance
<?php
$cars =array ("Volvo", "BMW", "Toyota");
Rsort ($cars);
?>
The following instance arranges the elements in the $numbers array in descending order of numbers:
Instance
<?php
$numbers =array (4,6,2,22,11);
Rsort ($numbers);
?>
Asort ()-Sorts the array in ascending order based on the values of the arrays
The following instance sorts the associative array in ascending order based on the value of the array:
Instance
<?php
$age =array ("Peter" and "a", "Ben" = "Notoginseng", "Joe" and "43");
Asort ($age);
?>
Ksort ()-Melt Kim the array in ascending order based on the keys of the arrays
The following instance sorts the associative array in ascending order, based on the key of the array:
Instance
<?php
$age =array ("Peter" and "a", "Ben" = "Notoginseng", "Joe" and "43");
Ksort ($age);
?>
Arsort ()-sorts arrays in descending order based on the values of the array
The following instance sorts the associative array in descending order, based on the value of the array:
Instance
<?php
$age =array ("Peter" and "a", "Ben" = "Notoginseng", "Joe" and "43");
Arsort ($age);
?>
Krsort ()-descending order of arrays based on the keys of the array
The following instance sorts the associative array in descending order, based on the key of the array:
Instance
<?php
$age =array ("Peter" and "a", "Ben" = "Notoginseng", "Joe" and "43");
Krsort ($age);
?>
PHP array sorting