phpasort

asort results in wrong order


This seems so elementary ..
I have an associative array defined in line 2.
I call asort() in line 6 (case insensitive)
My results are in line 8, which are wrong.
What I expect/want is in line 10.
Maybe I should sleep on it?

<?php
  $a1 = array( 1 => 'Brad', 2 => 'Chas', 3 => 'adam');
  print_r($a1);
  // prints "Array ( [1] => Brad [2] => Chas [3] => adam )"
  echo "<br >\n";
  asort($a1, SORT_FLAG_CASE || SORT_NATURAL);
  print_r($a1); //
  // prints "Array ( [3] => adam [2] => Chas [1] => Brad )" - wrong
  // what I expect/want is
  //        "Array ( [3] => adam [1] => Brad [2] => Chas )"
?>

Solution

  • Please replace || with | in

    asort($a1, SORT_FLAG_CASE || SORT_NATURAL);
    

    I hope this may help