Created
December 10, 2018 15:25
-
-
Save frantzmiccoli/bd03395b8fc831c67828718192c214b8 to your computer and use it in GitHub Desktop.
Just a quick demo highlighting that PHP doesn't preserve same-value keys order while running an associative 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
<?php | |
$a = []; | |
$threshold = 120; | |
while (count($a) < 400) { | |
$v = count($a) > $threshold ? 'a' : 'b'; | |
$a[] = $v; | |
} | |
asort($a); | |
// keys are preserved but their order within keys containing the same value is not. | |
var_dump($a); | |
die; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment