


Detailed explanation of php array_multisort() function_PHP tutorial
php tutorial array_multisort() function detailed explanation
Function bool array_multisort ( array &$arr [, mixed $arg = SORT_ASC [, mixed $arg = SORT_REGULAR [, mixed $...]]] )
Parameter description: The function sorts multiple arrays or multi-dimensional arrays
The first parameter is an array, and each subsequent parameter may be an array or the following sort order flag
SORT_ASC - Default, sort in ascending order
SORT_DESC - Sort in descending order
You can then specify the sorting type
SORT_REGULAR - Default. Arrange each item in regular order.
SORT_NUMERIC - Sort each item in numerical order.
SORT_STRING - Sort each item in alphabetical order.
Example code
$arr1 = array('10', 11, 100, 100, 'a');
$arr2 = array(1, 2, 3, '2', 5);
array_multisort($arr1, $arr2);
The result is:
$arr1
Array ( [0] => 10 [1] => a [2] => 11 [3] => 100 [4] => 100 )
# '10' is converted to the integer 10 when compared with 11, 100, 100, which is smaller than the other three numbers
# '10' is used as a string when compared with 'a'. Its first character '1' has an ascii code value of 49 which is less than 'a' (the ascii value is 97), so '10' is the smallest element
# When 'a' is compared with other three numbers, it is converted to an integer 0, which is smaller than the other three numbers
$arr2
Array ( [0] => 1 [1] => 5 [2] => 2 [3] => 2 [4] => 3 )
# $arr2 element 1 corresponds to $arr1 element '10' position, so it is ranked at [0] position
# $arr1[2] => 100, $arr1[3] => 100 correspond to $arr2 elements 3 and '2' respectively. 3 is greater than '2', so $arr1[2] corresponding to 2 => 100. The sorted subscript is
3, $arr1[3] corresponding to 3 => The index of 100 sorting is 4
Summary
1. The number of array elements participating in sorting remains the same
2. The corresponding positions of the sorted array elements are as follows: ‘10’ => 1, 11 => 2
3. The following array is sorted based on the order of the previous array
4. If the previous array encounters equal elements, compare the following array
Grammar
array_multisort(array1,sorting order,sorting type,array2,array3...)
参数 | 描述 |
---|---|
array1 | 必需。规定输入的数组。 |
sorting order | 可选。规定排列顺序。可能的值是 SORT_ASC 和 SORT_DESC。 |
sorting type | 可选。规定排序类型。可能的值是SORT_REGULAR、SORT_NUMERIC和SORT_STRING。 |
array2 | 可选。规定输入的数组。 |
array3 | 可选。规定输入的数组。 |
Tips and Notes
Note: String key names will be preserved, but numeric keys will be re-indexed, starting at 0 and increasing by 1.
Note: You can set the sort order and sort type after each array. If not set, each array parameter will use the default

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.
