- uasort: documentation ( source)
- print_r: documentation ( source)
<?php
class test {
protected $val;
public function __construct($val) {
$this->$val = $val;
}
public function getVal() {
return $this->val;
}
}
$arr = array(
'one' => new test(3),
'two' => new test(2),
'three' => new test(1)
);
uasort($arr, function (test $a, test $b) {
if ($a->getVal() == $b->getVal()) {
return 0;
}
return ($a->getVal() < $b->val()) ? -1 : 1;
});
print_r($arr);