serial array vs. hash....

From: Date: Wed, 09 Jan 2002 05:53:27 +0000
Subject: serial array vs. hash....
Groups: php.general 
Request: Send a blank email to php-general+get-79867@lists.php.net to get a copy of this message
Hi folks, Quick question about the performance implications of looking up info in a hash (associative array) vs. looking it up in a serial array. I have a script that will be running a function (actually several similar functions) up to 1500 times to verify that certain data values are in a valid list. My list might have anywhere from 2 to 100 valid values. 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. 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, and I intend to test the two techniques myself to find out, but I just thought I would check here to see if anyone could confirm or refute my hunch.... Thanks for your help, Eric

« previous php.general (#79867) next »