Skip to content

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

Advertisement

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

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top