in a very tight loop I need to access tenthousands of values in an array containing millions of elements. The key can be undefinied: In that case it shall be legal to return
Just a sudden idea that would have to be tested, but did you try using array_intersect_key()
to get the existing values and a array_merge to fill() the rest ? It would remove the need of a loop to access the data. Something like that :
$searched_keys = array ('key1' => null, 'key2' => null); // the list of the keys to find
$exiting_values = array_intersect_key($lookup_table, $searched_keys);
$all_values = array_merge($searched_keys, $exiting_keys);
Please note that I did not tried it performance-wise.