- print_r: documentation ( source)
- uksort: documentation ( source)
<?php
class myClass
{
private $a = [
'foo-test' => [1],
'-' => [2],
'bar-test' => [3]
];
private function _mySort($x, $y)
{
print_r($this->a);
if (!isset($this->a[$x])) {
throw new Exception('Missing X: "' . $x . '"');
}
if (!isset($this->a[$y])) {
throw new Exception('Missing Y: "' . $y . '"');
}
return ($x == 'foo-test' ? -1 : ($x == 'bar-test' ? 1 : 0));
}
public function __construct()
{
uksort($this->a, [$this, '_mySort']);
}
}
new myClass();