Use the in_array() function.

$array = array('kitchen', 'bedroom', 'living_room', 'dining_room');

if (in_array('kitchen', $array)) {
    echo 'this array contains kitchen';
}
Answer from Wiseguy on Stack Overflow
🌐
W3Schools
w3schools.com › php › func_array_in_array.asp
PHP in_array() Function
connection_aborted() connection_status() connection_timeout() constant() define() defined() die() eval() exit() get_browser() __halt_compiler() highlight_file() highlight_string() hrtime() ignore_user_abort() pack() php_strip_whitespace() show_source() sleep() sys_getloadavg() time_nanosleep() time_sleep_until() uniqid() unpack() usleep() PHP MySQLi · affected_rows autocommit change_user character_set_name close commit connect connect_errno connect_error data_seek debug dump_debug_info errno error error_list fetch_all fetch_array fetch_assoc fetch_field fetch_field_direct fetch_fields fetch_l
Discussions

php - Check if string contains a value in array - Stack Overflow
I am trying to detect whether a string contains at least one URL that is stored in an array. ... The string is entered by the user and submitted via PHP. More on stackoverflow.com
🌐 stackoverflow.com
php - Check if a specific array element contains a whitelisted value - Stack Overflow
Here is a PHP demo. ... array_key_exists() checks for array keys while the latter $search_array contains associative array. No doubt it won't work. You should array_flip() it first. More on stackoverflow.com
🌐 stackoverflow.com
PHP Code Golf: Detect if string contains an element from array.
Throughout my 6+ year career I have had to write code for checking if one or more strings exist in another string. When doing this in the past, I… More on reddit.com
🌐 r/PHP
22
6
November 17, 2017
Is there a reason why needle-haystack argument order in builtin PHP functions are inconsistent?
PHP, especially in the early days, was developed in a way where when somebody had a problem they create the patch and pushed it (or well, in CVS, committed it) without design oversight or plan or whatever. In quite a bunch of cases this follows what C does (as many parts of "classic" PHP are directly inspired by C, most extensions are thin wrappers of C libraries etc.) This model worked well to cover lots of ground instead of arguing in committee, which allowed the quick growth PHP had, but lead to some inconsistencies. However, if you look at it in depth it's not totally bad, most cases are similar (with string functions haystack often comes first, with array functions mostly needle first) More on reddit.com
🌐 r/PHP
65
52
May 16, 2024
🌐
PHP
php.net › manual › en › function.in-array.php
PHP: in_array - Manual
<?php // Example array $array = array( 'egg' => true, 'cheese' => false, 'hair' => 765, 'goblins' => null, 'ogres' => 'no ogres allowed in this array' ); // Loose checking -- return values are in comments // First three make sense, last four ...
🌐
Delft Stack
delftstack.com › home › howto › php › php array contains
How to Check if Array Contains a Value in PHP | Delft Stack
February 2, 2024 - PHP in_array() is compatible with all PHP4 and above versions. The functions foreach loop and strpos() can be used together to check if the string contains a value from the array.
🌐
CSS-Tricks
css-tricks.com › snippets › php › php-array-contains
PHP Array Contains | CSS-Tricks
September 13, 2009 - → PHP Array Contains · Chris Coyier on Sep 13, 2009 · Check if value is in array and outputs Yes or No · <?php $names = array( 'Bob', 'Jim', 'Mark' ); echo 'In Array? '; if (in_array(‘foo’, $names)) echo 'Yes'; else echo 'No'; ?> Jimbo · Permalink to comment# September 1, 2010 ·
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-determine-if-an-array-contains-a-specific-value-in-php
How to determine if an array contains a specific value in PHP? - GeeksforGeeks
June 6, 2024 - <?php //array containing elements $names = array('Geeks', 'for', 'Geeks'); //search element $item = 'Geeks'; if(in_array($item, $names)){ //the item is there echo "Your element founded"; } else{ //the item isn't there echo "Element is not found"; ...
🌐
PHP Tutorial
phptutorial.net › home › php tutorial › php in_array
PHP in_array() Function - PHP Tutorial
April 6, 2025 - The following example uses the in_array() function to find the number 15 in the $user_ids array. It returns true because the in_array() function compares the values using the loose comparison (==): <?php $user_ids = [10, '15', '20', 30]; $result = in_array(15, $user_ids); var_dump($result); // ...
🌐
ReqBin
reqbin.com › code › php › prd64jee › php-in-array-example
How to check if an element exists in a PHP array?
If the parameter is set to TRUE, ... is FALSE. In this PHP Search In Array example, we use the in_array() function to check whether the given value exists in the array....
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-in_array-function
PHP in_array() Function - GeeksforGeeks
June 2, 2025 - The in_array() function in the PHP works in the following ways: By default, in_array() performs a loose comparison (==) between $needle and the array elements. If $strict is true, it performs a strict comparison (===) which checks both the value and the type. This behavior is important when searching in arrays with mixed types (e.g., strings, integers, floats). Now, let us understand with the help of the example:
🌐
W3Docs
w3docs.com › php
PHP: Check if an array contains all array values from another array
<?php $arr1 = ["a", "b", "c"]; $arr2 = ["a", "b"]; if (empty(array_diff($arr2, $arr1))) { echo "arr1 contains all values from arr2"; } else { echo "arr1 does not contain all values from arr2"; }
🌐
O'Reilly
oreilly.com › library › view › php-cookbook › 1565926811 › ch04s12.html
4.11. Checking if an Element Is in an Array - PHP Cookbook [Book]
November 20, 2002 - 4.11. Checking if an Element Is in an ArrayProblem You want to know if an array contains a certain value. SolutionUse in_array( ) : if (in_array($value, $array)) { // an... - Selection from PHP Cookbook [Book]
Authors   David SklarAdam Trachtenberg
Published   2002
Pages   640
🌐
Sling Academy
slingacademy.com › article › how-to-check-if-an-array-contains-a-value-in-php
How to check if an array contains a value in PHP - Sling Academy
This tutorial covers several methods from the simple in_array function to more advanced techniques. The in_array() function is the most straightforward way to check if a value exists in an array. It returns true if the value is found in the array and false otherwise.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-check-if-a-value-exists-in-an-array-in-php.php
How to Check If a Value Exists in an Array in PHP
Let's take a look at an example to understand how it basically works: Try this code » · <?php $zoo = array("Lion", "Elephant", "Tiger", "Zebra", "Rhino", "Bear"); if(in_array("Elephant", $zoo)){ echo "The elephant was found in the zoo."; } ...
🌐
Phpmentoring
phpmentoring.org › blog › php-in-array-function
Php in_array() Function | How To Check If A Value Is In An Array PHP
Strict comparison is also known as “===” in PHP. As we pointed out above the in_array() function returns true if the value exists in the array, and false if not. If the value being compared ($needle) is a string, the in_array() function will use case-sensitivity by default when comparing to values in the array ($haystack). In this example the first if statement passes fine, but the second if statement will fail.
🌐
w3resource
w3resource.com › php › function-reference › array_key_exists.php
PHP: array_key_exists() function - w3resource
Value Type: Boolean · Example: <?php $array1=array("Orange" => 100, "Apple" => 200, "Banana" => 300, "Cherry" => 400); if (array_key_exists("Banana",$array1)) { echo "Array Key exists..."; } else { echo "Array Key does not exist..."; } ?> Output: ...
🌐
Reintech
reintech.io › blog › comprehensive-guide-php-in-array-function
A Comprehensive Guide to PHP's `in_array()` Function | Reintech media
January 28, 2026 - While conceptually simple, understanding its behavior—particularly around type coercion and performance characteristics—is essential for writing robust PHP applications. bool in_array(mixed $needle, array $haystack, bool $strict = false)