helpers\BaseArrayHelper multisort()

multisort() public static method

Sorts an array of objects or arrays (with the same structure) by one or several keys.

public static void multisort ( &$array, $key, $direction = SORT_ASC, $sortFlag = SORT_REGULAR )
$array array

The array to be sorted. The array will be modified after calling this method.

$key string|Closure|array

The key(s) to be sorted by. This refers to a key name of the sub-array elements, a property name of the objects, or an anonymous function returning the values for comparison purpose. The anonymous function signature should be: function($item). To sort by multiple keys, provide an array of keys here.

$direction integer|array

The sorting direction. It can be either SORT_ASC or SORT_DESC. When sorting by multiple keys with different sorting directions, use an array of sorting directions.

$sortFlag integer|array

The PHP sort flag. Valid values include SORT_REGULAR, SORT_NUMERIC, SORT_STRING, SORT_LOCALE_STRING, SORT_NATURAL and SORT_FLAG_CASE. Please refer to PHP manual for more details. When sorting by multiple keys with different sort flags, use an array of sort flags.

throws yii\base\InvalidParamException

if the $direction or $sortFlag parameters do not have correct number of elements as that of $key.

doc_Yii
2016-10-30 17:04:28
Comments
Leave a Comment

Please login to continue.