Sorts an array of objects or arrays based on one or more orderby arguments.
Parameters
$input_list
arrayrequired- An array of objects or arrays to sort.
$orderby
string|arrayoptional- Either the field name to order by or an array of multiple orderby fields as
$orderby => $order
.
Default:
array()
$order
stringoptional- Either
'ASC'
or'DESC'
. Only used if$orderby
is a string. Default'ASC'
.Default:
'ASC'
$preserve_keys
booloptional- Whether to preserve keys.
Default:
false
Source
function wp_list_sort( $input_list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
if ( ! is_array( $input_list ) ) {
return array();
}
$util = new WP_List_Util( $input_list );
return $util->sort( $orderby, $order, $preserve_keys );
}
Changelog
Version | Description |
---|---|
4.7.0 | Introduced. |
Example of usage: