ຫົວຫຼັກ PHP krsort()

ກໍານົດ

ຈັດອອກອັນດັບລຳດັບການກັບຄຳສັ່ງວິກາຍສະເພາະຫຼັງ:

<?php
$age=array("Bill"=>"60","Steve"=>"56","mark"=>"31");
krsort($age);
?>

ການດຳເນີນການພິມ

ການກໍານົດ ແລະ ການນໍາໃຊ້

ຫົວຫຼັກ krsort() ການຈັດອອກອັນດັບລຳດັບການກັບຄຳສັ່ງວິກາຍສະເພາະຫຼັງ.

Tips:Please use ksort() The function sorts the associated array in ascending order by key name.

Tips:Please use arsort() The function sorts the associated array in descending order by key value.

Syntax

krsort(array,sortingtype);
Parameters Description
array Required. Specifies the array to be sorted.
sortingtype

Optional. Specifies how to sort the elements/items of the array. Possible values:

  • 0 = SORT_REGULAR - Default. Sort each item in the standard order (Standard ASCII, do not change type).
  • 1 = SORT_NUMERIC - Treat each item as a number.
  • 2 = SORT_STRING - Treat each item as a string.
  • 3 = SORT_LOCALE_STRING - Treat each item as a string, based on the current locale (can be changed via setlocale()).
  • 4 = SORT_NATURAL - Treat each item as a string, using a natural sorting similar to natsort().
  • 5 = SORT_FLAG_CASE - Can combine (bitwise OR) SORT_STRING or SORT_NATURAL to sort strings without case sensitivity.

Description

The krsort() function sorts an array in reverse order by key, retaining the original keys of the array.

The optional second parameter includes additional sorting flags.

If successful, returns TRUE, otherwise returns FALSE.

Technical Details

Return value: If successful, returns TRUE, if failed, returns FALSE.
PHP Version: 4+