Funksheni sort() ya PHP

Mfano

Taslimu ya upanishaji wa upya wa lugha kwa vifaa $cars:

<?php
$cars=array("Volvo","BMW","Toyota");
sort($cars);
?>

Matokeo ya Kuendeleza

Muundo na matumizi

Funksheni sort() inafanya taslimu ya msingi wa ndani ya orodha kwa uharibifu wa msingi.

Mwongozo:Funksheni hii inaingiza jina la msingi kwa kiwango cha kifaa. Jina la msingi la kuzaliwa litachukuliwa.

If successful, it returns TRUE, otherwise it returns FALSE.

Tip:Use rsort() The function sorts the index array in descending order.

Syntax

sort(array,sortingtype);
Parameter Description
array Required. Specify the array to be sorted.
sortingtype

Optional. Specify how to compare array elements/items. Possible values:

  • 0 = SORT_REGULAR - Default. Arrange each item in regular 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 through setlocale()).
  • 4 = SORT_NATURAL - Treat each item as a string, using a natural sorting similar to natsort().
  • 5 = SORT_FLAG_CASE - Can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings without case sensitivity.

Mafunzo ya Teknolojia

Matokeo: If successful, it returns TRUE, if not, it returns FALSE.
Mwaka wa PHP: 4+

Mfano zaidi

Mfano 1

Kuendeleza matukio ya mifunguo ya orodha ya $numbers kwa orodha ya nambari ya kina:

<?php
$numbers=array(4,6,2,22,11);
sort($numbers);
?>

Matokeo ya Kuendeleza