PHP: usort magic


usort is very useful when one wants to combine or manipulate the results especially received from the db.

say for example we have an array named $displayProduct and we want to sort by the associative array call ‘order’

usort($displayProduct, function($a, $b) {return ($a['order'] < $b['order']) ? -1 : 1; });
Like it.? Share it:

Comments are closed.