note 60399 added to function.get-defined-constants
| From: | php-general at lists dot php dot net | Date: | Thu, 05 Jan 2006 19:29:09 +0000 |
| Subject: | note 60399 added to function.get-defined-constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101271@lists.php.net to get a copy of this message | ||
If you want to filter through and return only the prefix for your constants (i.e. you have constants
with a naming scheme), then you can use this quick little function. It comes in handy for debugging.
<?php
function returnConstants ($prefix) {
foreach (get_defined_constants() as $key=>$value)
if (substr($key,0,strlen($prefix))==$prefix) $dump[$key] = $value;
if(empty($dump)) { return "Error: No Constants found with prefix
'".$prefix."'"; }
else { return $dump; }
}
?>
Example:
<?php
define("SITENAME_OPTION_ONE",true);
define("SITENAME_OPTION_TWO",false);
define("SITENAME_URL","foo");
print_r(returnConstants("SITENAME_OPTION"));
?>
Will return:
Array
(
[SITENAME_OPTIONONE] => 1
[SITENAME_OPTIONTWO] =>
)
----
Manual Page -- http://www.php.net/manual/en/function.get-defined-constants.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60399
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60399&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60399&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60399&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60399&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60399&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60399&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60399&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60399&report=yes
Search -- http://master.php.net/manage/user-notes.php