PHP 8.5.0 Alpha 1 available for testing

Voting

: min(four, zero)?
(Example: nine)

The Note You're Voting On

Anonymous
9 years ago
An associative array with known keys can be easily custom sorted using a switch statement in the callback:

NB ksort can be used beforehand to ensure expected results

ksort($array);

uksort($array, function ($a) {
switch($a) {
case 'pepperoni':
return 0;
case 'beef':
return 1;
case 'chicken':
return 2;
case 'ham':
return 3;
case 'vegetarian':
return 4;
}
});

<< Back to user notes page

To Top