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

//Example for sorting by values for an alphanumeric array also having case-sensitive data

 $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
 )

多维数组排序:
http://blog.csdn.net/zhezhebie/article/details/72158753

你可能感兴趣的:(php)