Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

array_multisort()

Sort arrays together by position, using later columns to break ties.

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

Syntax

array_multisort(array &$array, mixed ...$rest): bool

Sort arrays together by position, using later columns to break ties. All columns must have the same length. Direction and comparison flags apply to the preceding column. Here rank is numeric ascending and labels break ties in ascending string order. Integer keys are reindexed, while string keys remain associated with their values. PHP 8.4 declares a boolean return and a successful sort returns true.

Signature

array_multisort(array &$array, mixed ...$rest): bool

Example output

[[1,1,2],["A","B","C"]]

Examples

<?php
$rank = [2,1,1];
$label = ['C','B','A'];
array_multisort($rank, SORT_ASC, SORT_NUMERIC, $label, SORT_ASC, SORT_STRING);
echo json_encode([$rank, $label]);

Result

[[1,1,2],["A","B","C"]]

Sources