Home > Article > Backend Development > How to Check if an Array Value Is One of Several Whitelisted Options in PHP?
Whitelisting Array Values
When working with arrays, ensuring that certain elements adhere to a predefined set of values is crucial for data integrity. In this specific case, you want to determine if the value of $something['say'] is either 'bla' or 'omg'.
Using in_array()
PHP offers the in_array function to simplify this task. It takes two arguments:
If the value is found within the array, in_array returns true. This can be applied to your case:
if (in_array("bla", $something)) { echo "has bla"; }
Additional Considerations
The above is the detailed content of How to Check if an Array Value Is One of Several Whitelisted Options in PHP?. For more information, please follow other related articles on the PHP Chinese website!