function msort($list, $method)Arcanist Technical Documentation ()
function msort($list, $method)
Arcanist Technical Documentation ()
Sort a list of objects by the return value of some method. In PHP, this is often vastly more efficient than usort() and similar.
// Sort a list of Duck objects by name. $sorted = msort($ducks, 'getName');
It is usually significantly more efficient to define an ordering method on objects and call msort() than to write a comparator. It is often more convenient, as well.
NOTE: This method does not take the list by reference; it returns a new list.
Parameters
list | $list | List of objects to sort by some property. |
string | $method | Name of a method to call on each object; the return values will be used to sort the list. |
Return
list | Objects ordered by the return values of the method calls. |
- Defined
- src/utils/utils.php:394