How to Check If a Value Exists in An Array in PHP

Q. How do I check if a specific value exists in an array in PHP. Write a sample PHP program to check if a value exists in an array.

Using PHP in_array() function

Use PHP in_array() function to check whether a specific value exists in an array or not.

Here is an sample PHP program, initialized an array with few element. Then check if an element is available in the defined array.

Example

Output:

Green element found in colors array

The post How to Check If a Value Exists in An Array in PHP appeared first on TecAdmin.

array General Articles PHP TecAdmin