1)sort() - sort arrays in ascending order
2)rsort() - sort arrays in descending order
3)ksort() - sort associative arrays in ascending order, according to the key
4)arsort() - sort associative arrays in descending order, according to the value
5)krsort() - sort associative arrays in descending order, according to the key
code examples :
<?php
$cars = array("Volvo", "BMW", "Toyota");
$clength = count($cars);
echo "<br>"."Before sort"."<br>";
for($i = 0; $i < $clength; $i++) {
echo $cars[$i];
echo "<br>";
}
sort($cars);
echo "<br>"."after sort"."<br>";
for($i = 0; $i < $clength; $i++) {
echo $cars[$i];
echo "<br>";
}
?>
output :
2)rsort() - sort arrays in descending order
3)ksort() - sort associative arrays in ascending order, according to the key
4)arsort() - sort associative arrays in descending order, according to the value
5)krsort() - sort associative arrays in descending order, according to the key
code examples :
<?php
$cars = array("Volvo", "BMW", "Toyota");
$clength = count($cars);
echo "<br>"."Before sort"."<br>";
for($i = 0; $i < $clength; $i++) {
echo $cars[$i];
echo "<br>";
}
sort($cars);
echo "<br>"."after sort"."<br>";
for($i = 0; $i < $clength; $i++) {
echo $cars[$i];
echo "<br>";
}
?>
output :
No comments:
Post a Comment