- var_dump: documentation ( source)
- uasort: documentation ( source)
<?php
const REQUIRED = 1;
const OPTIONAL = 2;
const IS_ARRAY = 4;
$args = [
'a' => [IS_ARRAY],
'b' => [OPTIONAL],
'c' => [REQUIRED],
'd' => [REQUIRED]
];
uasort(
$args,
function ($a, $b) {
if ($a[0] & IS_ARRAY === IS_ARRAY) { echo "a is array\n";
return -1;
}
if ($b[0] & IS_ARRAY === IS_ARRAY) { echo "b is array\n";
return 1;
}
if ($a[0] & OPTIONAL === OPTIONAL) { echo "a is optional\n";
return -1;
}
if ($b[0] & OPTIONAL === OPTIONAL) { echo "b is optional\n";
return 1;
}
return 0;
}
);
var_dump($args);