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.

Advertisement

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
Share.
Leave A Reply

Exit mobile version