Skip to content

Instantly share code, notes, and snippets.

@sheryarshirazi
Created April 20, 2016 20:13
Show Gist options
  • Save sheryarshirazi/feff60364649799af644011a92cdba29 to your computer and use it in GitHub Desktop.
Save sheryarshirazi/feff60364649799af644011a92cdba29 to your computer and use it in GitHub Desktop.
Find Constant Array key Names
<?php namespace yourName;
/**
* return constant array key
* @param constant $const constant array name
* @param int $index index of constant array key value (in my case its int)
* @return string key name (string in my case)
*/
function getConstantArrayNames($const, $index) {
$x = get_defined_constants(true);
foreach ($x['user']['yourName\\'.$const] as $key => $value) {
if ($value == $index)
return $key;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment