Arranging integer cluster in PHP: Here, we will figure out how to sort an integer exhibit in climbing or plunging request in PHP?
Given an integer cluster and we need to sort them in climbing and slipping request in PHP.
Strategies to sort an exhibit:
In PHP, there are two strategies which are utilized to sort an exhibit,
- sort() – It is utilized to sort a cluster in rising request.
- rsort() – It is utilized to sort a cluster in the sliding request.
PHP code for arranging cluster in rising request
<?php
//declaring & initializing array of integers
$array = array(10, 80, 100, 11, 22, 21, 19, 10, 88, 89);
//sorting array in ascending order
sort ($array);
//printing array elements after sorting
foreach( $array as $num ){
echo $num."\n";
}
?>
Output
10
10
11
19
21
22
80
88
89
100
PHP code for arranging cluster in sliding request
<?php
//declaring & initializing array of integers
$array = array(10, 80, 100, 11, 22, 21, 19, 10, 88, 89);
//sorting array in descending order
rsort ($array);
//printing array elements after sorting
foreach( $array as $num ){
echo $num."\n";
}
?>
Output:
100
89
88
80
22
21
19
11
10
10