Home 2012 December

PHP Snippet of the day – Sort Object by field name

Published on December 1, 2012 by in PHP

If you find you need to sort an returned object this snippet will save your life.
/** * Sort array of objects by field.
* @param array $objects Array of objects to sort.
* @param string $on Name of field.
* @param string $order (ASC|DESC)
function sort_on_field(&$objects, $on, $order = ‘ASC’) {

 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
© Brainstorms of a Webdev