Changeset 11082 for trunk/src/bp-core/bp-core-functions.php
- Timestamp:
- 09/10/2016 05:14:34 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-functions.php
r11081 r11082 109 109 * 110 110 * @since 2.2.0 111 * 112 * @param array $items The items to be sorted. Its constituent items can be either associative arrays or objects. 113 * @param string|int $key The array index or property name to sort by. 114 * @param string $type Sort type. 'alpha' for alphabetical, 'num' for numeric. Default: 'alpha'. 111 * @since 2.7.0 Added $preserve_keys parameter. 112 * 113 * @param array $items The items to be sorted. Its constituent items 114 * can be either associative arrays or objects. 115 * @param string|int $key The array index or property name to sort by. 116 * @param string $type Sort type. 'alpha' for alphabetical, 'num' 117 * for numeric. Default: 'alpha'. 118 * @param bool $preserve_keys Whether to keep the keys or not. 119 * 115 120 * @return array $items The sorted array. 116 121 */ 117 function bp_sort_by_key( $items, $key, $type = 'alpha' ) { 118 usort( $items, array( new BP_Core_Sort_By_Key_Callback( $key, $type ), 'sort_callback' ) ); 122 function bp_sort_by_key( $items, $key, $type = 'alpha', $preserve_keys = false ) { 123 if ( true === $preserve_keys ) { 124 uasort( $items, array( new BP_Core_Sort_By_Key_Callback( $key, $type ), 'sort_callback' ) ); 125 } else { 126 usort( $items, array( new BP_Core_Sort_By_Key_Callback( $key, $type ), 'sort_callback' ) ); 127 } 119 128 120 129 return $items;
Note: See TracChangeset
for help on using the changeset viewer.