How to check a value exists in an array

How to check a value exists in an array is a general requirement when using array. We can do it by iterating through the array one by one and checking that the searched value exist or not. But now a days, everybody expects a short method means using built in functions in the language. PHP also provides the built in function in_array() for checking the value in an array. in_array — Checks if a value exists in an array (php4, php5) syntax

If the third parameter strict is set to TRUE then the in_array() function will also check the types of the searched value in the array. Return boolean value Returns TRUE if searched value is found in the array, FALSE otherwise. Note: in_array() is case-sensitive search. Examples:

By reading these examples, you can get proper understanding of using in_array() PHP function. If still have any doubt, you can write to us by commenting on the post, we will revert back to you with possible solution as soon as possible.

You Might Interested In

Leave a Reply

Enclose a code block like: <pre><code>Your Code Snippet</code></pre>.