Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

sort()

Sort values from low to high in place, discarding all original keys.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

sort(array &$array, int $flags = SORT_REGULAR): true

Sort values from low to high in place, discarding all original keys. SORT_NUMERIC orders quantities by numeric value without turning stored numeric strings into integers. The function returns true; the argument holds the reordered list.

Signature

sort(array &$array, int $flags = SORT_REGULAR): true

Example output

[true,["0","2","10"]]

Examples

<?php
$stock = ["large"=>"10","small"=>"2","none"=>"0"];
$ok = sort($stock,SORT_NUMERIC);
echo json_encode([$ok,$stock]);

Result

[true,["0","2","10"]]

Sources