php tutorial - PHP krsort Function - php programming - learn php - php code - php script

  • In PhP, the krsort function is mainly used in associative array.
  • The "krsort()" function is used to sort an array elements by the key in descending order.

php programming Syntax :

click below button to copy the code. php tutorial - team

php 7 Sample Code : sample php program

<!DOCTYPE html>
	    foreach ($var1 as $x => $x_value) 
	       echo "key=" .$x .",value=".$x_value;
click below button to copy the code. php tutorial - team

php program Code Explanation :

Code Explanation for krsort Function In PHP

  1. In this statement “$var1” variable is defining an associative array using array function with its keys such as “Lemon, Apple and Grape” and the values as “34,50, and 25”.
  2. The var1 value will be sorted using the krsort function where the array keys are sorted in ascending order.
  3. In this statement we use the for each loop that will be used for looping process in an associative array. The first variable of the for loop defines the array name “$var1” then “$x” defines the key, and “$x_value” defines the value.
  4. Echo statement is used to print the value of the sorted key and their values. Whereas, the “.” Dot symbol is used for concatenation of the string in php.

php coding Sample Output :

output for krsort Function In PHP

  1. Output shows the keys (Lemon, Apple and Grapes) are sorted in descending order (Lemon, Grapes and Apple) according to the values with its keys (34,25 & 50) as it is.

Related Searches to php krsort function

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add to your ad blocking whitelist or disable your adblocking software.