Assume I have the following code:
Code: Select all
function arrayLookup($array, $key) {
if (!array_key_exists($key, $array)) {
return $phrase;
}
return $array[$key];
}Is there a way to reduce the number of lookups to 1?
Here is what I would like to do:
Perform a single lookup that does the check but also gives you an index. If check if successful the second access can be done via the index to be immediate instead of going through hash table
regards
Jason