Created
September 22, 2020 15:24
-
-
Save smailliwcs/230743dc79cd4283fd4eabc89aa146cf to your computer and use it in GitHub Desktop.
Underscore.php mixin: sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array | |
( | |
[0] => 5 | |
[1] => 1 | |
[2] => 3 | |
[3] => 0 | |
[4] => 6 | |
[5] => 8 | |
[6] => 4 | |
[7] => 9 | |
[8] => 7 | |
[9] => 2 | |
) | |
Array | |
( | |
[0] => 0 | |
[1] => 1 | |
[2] => 2 | |
[3] => 3 | |
[4] => 4 | |
[5] => 5 | |
[6] => 6 | |
[7] => 7 | |
[8] => 8 | |
[9] => 9 | |
) | |
Array | |
( | |
[0] => 9 | |
[1] => 8 | |
[2] => 7 | |
[3] => 6 | |
[4] => 5 | |
[5] => 4 | |
[6] => 3 | |
[7] => 2 | |
[8] => 1 | |
[9] => 0 | |
) | |
Array | |
( | |
[0] => 5 | |
[1] => 1 | |
[2] => 3 | |
[3] => 0 | |
[4] => 6 | |
[5] => 8 | |
[6] => 4 | |
[7] => 9 | |
[8] => 7 | |
[9] => 2 | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
__()->mixin([ | |
"sort" => function ($items, $ascending = true) { | |
if ($ascending) { | |
sort($items); | |
} else { | |
rsort($items); | |
} | |
return $items; | |
} | |
]); | |
$numbers = __()->chain()->range(10)->shuffle()->value(); | |
print_r($numbers); | |
print_r(__($numbers)->sort()); | |
print_r(__($numbers)->sort(false)); | |
print_r($numbers); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment