In php, array_multisort() can sort multiple arrays at one time, or sort multi-dimensional arrays according to a certain dimension or multiple dimensions. It returns TRUE if successful and FALSE if failed.
bool array_multisort (array ar1 [, mixed arg [, mixed ... [, array ...]]] )
Returns TRUE if successful, FALSE if failed.
array_multisort() can be used to sort multiple arrays at once, or to sort multi-dimensional arrays according to one or more dimensions.
Associative (string) key names remain unchanged, but numeric key names will be re-indexed.
Example 1. Sort multidimensional array
The code is as follows | Copy code | ||||||||||||||||||||||||||||
); array_multisort($ar[0], SORT_ASC, SORT_STRING,$ar[1], SORT_NUMERIC, SORT_DESC); var_dump($ar);
In this example, after sorting, the first array will become "10", 100, 100, 11, "a" (treated as strings in ascending order). The second array will contain 1, 3, "2", 2, 1 (treated as numbers in descending order).
Example 3 Let’s take a comprehensive look at an example commonly used in applications.
For a detailed explanation of the array_multisort() function, please refer to http://www.bKjia.c0m/phper/php-function/39192.htm
Previous article:Using static variables in php functions_PHP tutorial
Next article:Detailed explanation of floating point (float) and integer (integer) data types in php_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>
|