
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
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); }
- Related Articles
- Check for the existence of a value in Java IdentityHashMap
- How to check existence of NaN keyword in an array JavaScript
- How to check for multidimensional nature of an array in PHP
- Check for the existence of key in an object using AngularJS
- Check for the existence of a key in Java IdentityHashMap
- How to check existence of an element in android listview?
- Check existence of an element in Java ArrayList
- How can I count true and false values in my PHP array?
- How can I count the documents in an array based on the value of a specific field?
- How to insert an array of values in a MySQL table with a single INSERT?
- How to get random value out of an array in PHP?
- In PHP, how can I add an object element to an array?
- How to iterate efficiently through an array of integers of unknown size in C#
- How can I get the length of a single unit on an axis in Matplotlib?
- How can I change the value of an instance of a row in MySQL table?

Advertisements