> -----Original Message-----
> From: Eric McKeown [mailto:[EMAIL PROTECTED]]
> Sent: 09 January 2002 05:53
> 
>   I
> could store the list in a conventional serial array...
> 
> $valid[0] = "Valid One";
> $valid[1] = "Valid Two";
> $valid[2] = "Valid Three";
> .
> and so on, and then use a for loop to iterate through the contents of
> the array each time that I need to check to see if I have a valid
> value.

Well, for a kick-off I'd use the built-in in_array() function rather than writing a 
for loop.

>  On the other hand, I could create a hash that looks like...
> 
> $valid["Valid One"] = "some value";
> $valid["Valid Two"] = "some other value";
> 
> and so on, and then simply check to see if the entry exists in the
> associative array in order to determine whether it is valid.  
> I suspect
> that the latter method would be much more efficient 

My suspicions would be the same as yours (but I haven't tested it).  If your "some 
value", "some other value", etc. are actually values that you are going to use, then 
this is clearly the right solution.  If you're just looking the values up, I might 
tend to the plain array solution simply for readability/understandability -- 
especially if the difference between in_array() and an associative lookup is small.

(BTW -- and pardon me if you already know this, but it's not clear from your query! -- 
if you do use the associative array method as a pure lookup, there's no need to assign 
different values for each index -- indeed, I'd probably go for something like this:

  $valid["Valid One"] = TRUE;
  $valid["Valid Two"] = TRUE;

as being the most obvious representation of your intentions!)

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to