php对一维数组字符串和数字进行排序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/PersonalM/article/details/82149442
$exampleArray1 = $exampleArray2 = array(
     0 => 'example1',
     1 => 'Example10',
     2 => 'example12',
     3 => 'Example2',
     4 => 'example3',
     5 => 'EXAMPLE10',
     6 => 'example10'
 );

default sorting

asort($exampleArray1);
result:
   Array
   (
   [5] => EXAMPLE10
   [1] => Example10
   [3] => Example2
   [0] => example1
   [6] => example10
   [2] => example12
   [4] => example3
   )

alphanumeric with case-sensitive data sorting by values

asort($exampleArray2, SORT_STRING | SORT_FLAG_CASE | SORT_NATURAL);
 result:
   Array
 (
     [0] => example1
     [3] => Example2
     [4] => example3
     [5] => EXAMPLE10
     [1] => Example10
     [6] => example10
     [2] => example12
 )

猜你喜欢

转载自blog.csdn.net/PersonalM/article/details/82149442