BP_Document::array_sort_by_column( $array, $column, int $direction = SORT_DESC )
Sort by column.
Description
Parameters
- $array
-
(Required)
- $column
-
(Required)
- $direction
-
(Optional)
Default value: SORT_DESC
Source
File: bp-document/classes/class-bp-document.php
public static function array_sort_by_column( $array, $column, $direction = SORT_DESC ) {
$new_array = json_decode( json_encode( $array ), true );
if ( 'date_created' === $column ) {
$mapping_arr = array_map( 'strtotime', array_column( $new_array, $column ) );
array_multisort( $mapping_arr, $direction );
} else {
$reference_array = array();
foreach ( $array as $key => $row ) {
$reference_array[ $key ] = $row[ $column ];
}
array_multisort( $reference_array, $direction, $array );
}
}
Changelog
| Version | Description |
|---|---|
| BuddyBoss 1.4.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.