- substr: 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 "No constant found.";
}
}
}
}
echo getConstantName('IMAGE', 1);