The code is as follows
代码如下 |
复制代码 |
$ar1 = array("10", 100, 100, "a");
$ar2 = array(1, 3, "2", 1);
array_multisort($ar1, $ar2);
var_dump($ar1);
var_dump($ar2);
?>
|
|
Copy code
|
代码如下 |
复制代码 |
$array = array('A','2','3','4','5','6','7','8','9','10','J','Q','K');
shuffle($array);//随机排序数组
print_r($array);//输出数组
|
$ar1 = array("10", 100, 100, "a");
$ar2 = array(1, 3, "2", 1);
代码如下 |
复制代码 |
$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1));
array_multisort ($ar[0], SORT_ASC, SORT_STRING,
$ar[1], SORT_NUMERIC, SORT_DESC);
?>
|
array_multisort($ar1, $ar2);
var_dump($ar1);
var_dump($ar2);
?>
Randomly sorted
The code is as follows |
Copy code |
|
$array = array('A','2','3','4','5','6','7','8','9','10','J ','Q','K');
shuffle($array);//Randomly sort array
print_r($array);//Output array
. Sort multidimensional array
The code is as follows
|
Copy code
|
$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1));
array_multisort ($ar[0], SORT_ASC, SORT_STRING,
$ar[1], SORT_NUMERIC, SORT_DESC);
?>
The most commonly used function for array sorting is sort($arr); its function is to sort the array keys in ascending order, and the sorted array key names are no longer the original key names, but the key names reset according to the new array. .
And sometimes we require more complex sorting. For example, if you sort by key name, the ksort($arr); function is used here, which will sort the array according to the key name and maintain the original key-value relationship. The corresponding asort($arr); function is to sort by key value and maintain the original key value relationship
In the same principle, the rsort(); arsort(); krsort(); function is the same as sort(); rsort(); ksort(); except that the sorting is in descending order.
Array operations are a very important foundation of PHP
http://www.bkjia.com/PHPjc/628997.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628997.htmlTechArticleThe main requirements of this article introduce the use of PHP's own functions to implement array sorting, including one-dimensional array ranking , multi-dimensional array sorting, random sorting, etc. array_multisort($a,$b), $a,$b is...
|
|
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