Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

PHP Warning: array_multisort (): Array sizes are inconsistent

Shulou Source: shulou.com Published: 2022-06-03 04:54:36 11月25日 Update

The array_multisort() function returns a sorted array. You can enter one or more arrays. Function sorts the first array, then the other arrays, and if two or more values are the same, it sorts the next array.

Encounter this error is caused by the inconsistency of the two arrays,

If it is a one-dimensional array and two-dimensional array sorting can be solved by the following method:

Using this method, it will be more troublesome to extract the age and store it in a one-dimensional array, and then arrange it in ascending order of age. The specific codes are as follows:

The copy code is as follows:

$ages = array();

foreach ($users as $user) {

$ages[] = $user['age'];

}

array_multisort($ages, SORT_ASC, $users);

Tags: Array sort code two function multiple method one-dimensional same consistent ascending order will be used for trouble two-dimensional storage input Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn NVidia Xiaomi Huawei