* Thus wrote Ren Fournier ([EMAIL PROTECTED]):
> 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.

Constants are more for the programmer to use within the program to
avoid hard coding arbitrary numbers embeded deep inside code.

You can use a combination of both Constants and arrays to achive
your task:

define('SEND_DS', 1);
define('SEND_DS_ACK', 2);
...

$lookup = array(
  SEND_DS      => 'SEND_DS',
  SEND_DS_ACK  => 'SEND_DS_ACK',
);


Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to