PHP – array_key_exists() vs in_array()

If you are using array_key_exists() instead of in_array(), believe it or not, it is a good choice you made. array_key_exists() is much faster than in_array().

array_key_exists($key, $array); // ideal

in_array( $key, array_keys( $array ) ) // This creates an array of keys from the given array first, which makes it much slower than array_key_exists()

Leave a Reply

Your email address will not be published. Required fields are marked *

*