Constant questions
| From: | René Fournier | Date: | Wed, 12 May 2004 17:29:13 +0000 |
| Subject: | Constant questions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-186020@lists.php.net to get a copy of this message | ||
Hi,
I have two questions involving Constants.
1. I want to refer to a refer to a Constant by its value (which is unique), and return its name. E.g.,:
define ("SEND_DS","1");
define ("SEND_DS_ACK","2");
define ("RESEND_DS","3");
define ("STARTUP_DS","12");
For example, if I receive "3", I would like to echo "RESEND_DS"--the name of the constant. Is there a simply way to do this? Or am I better using an Associative Array (which is what I was thinking)? Then I could such refer to an element by its key or value (both of which are unique). I suppose this more of a performance/elegance issue, than outright problem. Just curious what you think.
2. Let's say I have a Constant called MY_NAME, the value of which is "Rene", and I pass it to a function, such as:
function example ($val) {
echo ???????;
}
example (MY_NAME);
Such that the output will be MY_NAME. If I echo $val, the output will be Rene. But I want to see the constants Name, not Value. Any ideas?
Thanks.
...Rene