![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I most efficiently check for the existence of a single value in an array of thousands of values in PHP?
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, the function can be customized in the below manner −
function array_keys_exists(array $keys, array $arr) { return !array_diff_key(array_flip($keys), $arr); }
Advertisements