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; });

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.