- var_dump: documentation ( source)
- 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(53),
'two' => new test(200),
'three' => new test(100)
);
uasort($arr, function (\test $a, \test $b) {
echo 'comparing '.var_dump($a).' with '.var_dump($b);
if ($a->getVal() == $b->getVal()) {
return 0;
}
return ($a->getVal() < $b->val()) ? -1 : 1;
});
print_r($arr);