- substr: documentation ( source)
- var_dump: documentation ( source)
- get_defined_constants: documentation ( source)
<?php
function getConstantName($category, $constantNumber)
{
foreach (get_defined_constants() as $key => $value) {
if (strlen($key) > strlen($category)) {
if (substr($key, 0, strlen($category)) === $category) {
if ($value === $constantNumber) {
return $key;
}
return null;
}
}
}
}
var_dump( getConstantName('IMAGE', 1) );