A quick way of doing this has been shown below −
if (array_flip($set)[$value] !== null) { echo "something"; //take some action }
To customize the number of keys, you can customize it as follows−
function array_keys_exists(array $keys, array $arr) { return !array_diff_key(array_flip($keys), $arr); }
The above is the detailed content of In PHP, how do I check in the most efficient way if a specific value exists in an array containing thousands of values?. For more information, please follow other related articles on the PHP Chinese website!