krsort() function in PHP || PHP krsort function
×


krsort() function in php

1867

PHP krsort() function is used to sort an associative PHP array in descending order. It is an inbuilt function of PHP. This function sorts the array according to the keys.

Syntax

krsort($array,$type_of_sorting);

here,

1) $array is a PHP array which we want to sort. It is mandatory

2) $type_of_sorting is a numeric value that decides the type of comparing of array elements. It is optional. It has 6 possible values that specify 6 possible sorting orders.

  • SORT_REGULAR: If a value is 0 then the function compares array elements normally.
  • SORT_NUMERIC: If a value is 1 then the function compares array elements as a numeric value.
  • SORT_STRING: If a value is 2 then the function compares array elements as a string.
  • SORT_LOCALE_STRING: If a value is 3 then this function compares array elements as a string according to the current locale.
  • SORT_NATURAL: If a value is 4 then the function compares array elements as a string with the use of natural ordering.
  • SORT_FLAG_CASE: If a value is 5 then this function compares array elements according to value.

Example:

<?php
$arr=array("RAM"=>"22","SHYAM"=>"1","AJAY"=>"11","RADHA"=>"150","PARI"=>"15");
krsort($arr);
echo "<pre>";
print_r($arr);
?>

Output:



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments