bp_alpha_sort_by_key

Sort an array of objects or arrays by alphabetically sorting by a specific key/property.

Description

(array) bp_alpha_sort_by_key( (array) $items, (string|int) $key ); 

For instance, if you have an array of WordPress post objects, you can sort them by post_name as follows:

Returns (array)

$items The sorted array.

Parameters (2)

0. $items (array)
The items to be sorted. Its constituent items can be either associative arrays or objects.
1. $key (string|int)
The array index or property name to sort by.

Usage

  1. if ( !function_exists( 'bp_alpha_sort_by_key' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // The items to be sorted. Its constituent items can be either associative arrays or objects. 
  5. $items = array(); 
  6.  
  7. // The array index or property name to sort by. 
  8. $key = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_alpha_sort_by_key($items, $key); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-functions.php  
  1. function bp_alpha_sort_by_key( $items, $key ) { 
  2. return bp_sort_by_key( $items, $key, 'alpha' );