Changeset 10514 for trunk/src/bp-core/bp-core-functions.php
- Timestamp:
- 02/05/2016 02:41:22 AM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-core/bp-core-functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-functions.php
r10497 r10514 119 119 */ 120 120 function bp_sort_by_key( $items, $key, $type = 'alpha' ) { 121 usort( $items, create_function( '$a, $b', ' 122 $values = array( 0 => false, 1 => false, ); 123 $func_args = func_get_args(); 124 foreach ( $func_args as $indexi => $index ) { 125 if ( isset( $index->' . $key . ' ) ) { 126 $values[ $indexi ] = $index->' . $key . '; 127 } elseif ( isset( $index["' . $key . '"] ) ) { 128 $values[ $indexi ] = $index["' . $key . '"]; 129 } 130 } 131 132 if ( isset( $values[0], $values[1] ) ) { 133 if ( "num" === "' . $type . '" ) { 134 $cmp = $values[0] - $values[1]; 135 } else { 136 $cmp = strcmp( $values[0], $values[1] ); 137 } 138 139 if ( 0 > $cmp ) { 140 $retval = -1; 141 } elseif ( 0 < $cmp ) { 142 $retval = 1; 143 } else { 144 $retval = 0; 145 } 146 return $retval; 147 } else { 148 return 0; 149 } 150 ') ); 121 usort( $items, array( new BP_Core_Sort_By_Key_Callback( $key, $type ), 'sort_callback' ) ); 151 122 152 123 return $items;
Note: See TracChangeset
for help on using the changeset viewer.