- get_defined_constants: documentation ( source)
- array_keys: documentation ( source)
- usort: documentation ( source)
<?php
$consts = get_defined_constants();
$consts = array_keys($consts);
usort($consts, function($a, $b) {
$aLen = strlen($a);
$bLen = strlen($b);
if ($aLen === $bLen) {
return 0;
}
return $aLen < $bLen ? 1 : -1;
});
foreach($consts as $const) {
echo strlen($const) . ": " . $const . "\n";
}