PHP multi-dimensional array sorting can be processed with the array_multisort() function. The array_multisort() function can be used to sort multiple items at once. Arrays are sorted, or multi-dimensional arrays are sorted according to a certain dimension or multiple dimensions. The associated (string) key names remain unchanged, but the numeric key names will be re-indexed
Sort order flag:
SORT_ASC - Sort in ascending order
SORT_DESC - Sort in descending order
Sorting type flag:
SORT_REGULAR - Compare items in the usual way
SORT_NUMERIC - Compare items numerically
SORT_STRING - Compare items by string
Example 1. Sort multiple arrays
The code is as follows | |||||||||||||||||||||||||||||||||||||
$ar1 = array("10", 100, 100, "a");
var_dump($ar1); In this example, after sorting, the first array will contain "10", "a", 100, 100. The second array will contain 1,1,"2",3. The order of the items in the second array is exactly the same as the order of the corresponding items (100 and 100) in the first array. But none of these can specify which key value to rank. Below I have compiled a few functions and algorithms, all of which are good. Sample code
例子二
例子3
例如有下列这样一个数组:
source:php.cn
Previous article:Today's News Network WeChat version (dede core) source code latest version v5.7, dedev5.7_PHP tutorial
Next article:Use PHP to add shopping products, PHP to add shopping products_PHP tutorial
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|