PHP rsort() function with example

PHP rsort() function with example

PHP rsort() work: Here, we will find out about the rsort() work with the example in PHP?

PHP rsort() work

rsort() work is utilized to sort a recorded exhibit in plummeting request.

In the event that cluster components are numeric, it sorts dependent on the numbers, if exhibit components are the string, it sorts dependent on the letters in order and if the cluster contains numeric values and content/strings, it sorts components dependent on the letters in order.

It doesn’t restore an arranged cluster, it sorts the info exhibit.

Syntax:

    rsort(array, [mode]);

Here,

  • cluster is an info exhibit
  • the mode is a discretionary parameter, its default value is 0, it has the following values:
    • 0 – It is utilized to think about things ordinarily
    • 1 – It is utilized to analyze things numerically
    • 2 – It is utilized to think about things as strings
    • 3 – It is utilized to look at things as present district strings
    • 4 – It is utilized to analyze things as strings (regular requesting)

Example:

    Input:
    $arr1 = array(105, 108, 101, 100, 90);

    Output:
    arr1 (sorted)...
    Array
    (    
        [0] => 108  
        [1] => 105  
        [2] => 101  
        [3] => 100  
        [4] => 90   
    )

PHP Code:

<?php    
    $arr1 = array(105, 108, 101, 100, 90);
    $arr2 = array("Kishan", "Durgesh", "Aakash", "Manish", "Ashwin");
	
    sort($arr1);
    print ("arr1 (sorted)...\n");
    print_r ($arr1);

    sort($arr2);
    print ("arr2 (sorted)...\n");
    print_r ($arr2);    
?>

Output:

arr1 (sorted)...
Array
(    
    [0] => 90   
    [1] => 100  
    [2] => 101  
    [3] => 105  
    [4] => 108  
)    
arr2 (sorted)...
Array
(    
    [0] => Ashwin
    [1] => Manish
    [2] => Kishan
    [3] => Durgesh
    [4] => Aakash
)

Recent Posts

error: Alert: Content is protected!!