Voting

: max(eight, three)?
(Example: nine)

The Note You're Voting On

mvs dot php at gmail dot com
10 years ago
To naturally sort by array key, the uksort function can be used.

<?php

echo "Sort by keys\n";
$smoothie = array('orange' => 1, 'apple' => 1, 'yogurt' => 4, 'banana' => 4);
print_r($smoothie);
uksort( $smoothie, 'strnatcmp');
print_r($smoothie)

?>

Output:

Sort by keys
Array
(
[orange] => 1
[apple] => 1
[yogurt] => 4
[banana] => 4
)
Array
(
[apple] => 1
[banana] => 4
[orange] => 1
[yogurt] => 4
)

See http://php.net/manual/en/function.uksort.php for more information about uksort and http://php.net/strnatcmp for usage of strnatcmp.

<< Back to user notes page

To Top