3000 explained code solutions for 75 technologies

phpSort array of objects by specific property

usort($objs, function($a, $b) { return $a->val <=> $b->val; });ctrl + c

this function sorts specified array by custom fiven function


array of objects to sort (this variable will contain sorted array after sorting)

function($a, $b)

custom function will get $a and $b, which are two objects from array to compare

$a->val <=> $b->val

compare properties of objects