To order multi-dimensional arrays of PHP, you can use the built-in functions in PHP: Array_multisort ();
Syntax: Array_multisort (array1,sorting order,sorting type,array2,array3 ...)
Parameter description
Array1 required. Specifies the input array.
Sorting order is optional. Specify the order of arrangement. The possible values are SORT_ASC and Sort_desc.
Sorting type is optional. Specifies the sort type. The possible values are Sort_regular, Sort_numeric, and sort_string.
Array2 is optional. Specifies the input array.
Array3 is optional. Specifies the input array.
Instance:
1<?PHP2 $data=Array();//A two-dimensional array to sort3 $randChar= "ABCDEFGHIJKLMNOPQRSTUWVXYZ";4 for($i= 0;$i<100;$i++){5 $randn=Rand(100,999);6 $RANDC=$randChar[Rand(0,25)];7 $data[] =Array($RANDC.$randn,$randn,$randn.$RANDC);8 }9 $num=Array();//The array to sort must be extracted from the $dataTen for($i= 0;$i<100;$i++){ One $num[] =$data[$i][2]; A } - Array_multisort($num, Sort_numeric,$data);//sorting, sorted by number
- Echo"<pre>"; the Print_r($data); - Echo"</pre>";
$data will generate a two-dimensional array, $num must be extracted from the $data array.
Personal understanding, although did not see the inside of the code: first use the bubble sort algorithm to arrange a one-dimensional array $num, and then use a for loop to $num with the two-dimensional array $data extracted data to do if judgment. If, for equality, the data is added to the new array. The following larger image can also implement the Array_multisort function
Use PHP to sort a multidimensional array of dimensions.