Since the version 4.1.0 PHP sort is not stable due to sorting algorithm, which cannot take into account both value and key. You have to use your now implementation of comparison considering key in case of equal values. For example you can modify original array values into (key, value) pairs,...
Just use sort() which won't maintain key association. $array = array(399, 349); sort($array); print_r($array); // Array ( [0] => 349 [1] => 399 ) Demo...
Please replace || with | in asort($a1, SORT_FLAG_CASE || SORT_NATURAL); I hope this may help...