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
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ function.in-array.php
PHP: in_array - Manual
Returns true if needle is found in the array, false otherwise. ... <?php $os = array("Mac", "NT", "Irix", "Linux"); if (in_array("Irix", $os)) { echo "Got Irix"; } if (in_array("mac", $os)) { echo "Got mac"; } ?>
๐ŸŒ
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 Code Golf: Detect if string contains an element from array.
There has been many use cases in the past so in some cases using a function that is case sensitive would have been the best route. But as far as this post goes, Iโ€™m just interested to see how the PHP community approach this. ... This will work only if you can depend on your array values having ... More on reddit.com
๐ŸŒ r/PHP
22
6
November 17, 2017
How to check if Array Contains a Specific Word in PHP
Well, if @return boolean, then it shouldn't return NULL on a non-existence. Here is an example that some people may see as "less overviewable", but maybe "fancier". Didn't test speed. I probally should have added a DocBlock to it, so it's a bit more understandable. It's filtering the array for the stripos !== FALSE output and then checks if the array then is empty or not. This could be worse when a big array is checked. The foreach would return true immediatly. Url: http://sandbox.onlinephpfunctions.com/code/663313f19f85747f83113d1ab10665cd8000d1a4 P.S. If you didn't understand my first sentence: add a return false after the foreach ;) More on reddit.com
๐ŸŒ r/PHP
19
0
April 11, 2017
๐ŸŒ
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
๐ŸŒ
Reddit
reddit.com โ€บ r/php โ€บ php code golf: detect if string contains an element from array.
r/PHP on Reddit: PHP Code Golf: Detect if string contains an element from array.
November 17, 2017 - There has been many use cases in the past so in some cases using a function that is case sensitive would have been the best route. But as far as this post goes, Iโ€™m just interested to see how the PHP community approach this. ... This will work only if you can depend on your array values having no regex characters.
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_string.asp
PHP Strings
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
Find elsewhere
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ php โ€บ prd64jee โ€บ php-in-array-example
How to check if an element exists in a PHP array?
July 27, 2023 - To check if an element exists in a PHP array, you can use the in_array($search, $array, $mode) function. The $search parameter specifies the element or value to search in the specified array and can be of a mixed type (string, integer, or other ...
๐ŸŒ
Laravel
laravel.com โ€บ docs โ€บ 12.x โ€บ artisan
Artisan Console | Laravel 12.x - The clean stack for Artisans and agents
Tinker utilizes an "allow" list to determine which Artisan commands are allowed to be run within its shell. By default, you may run the clear-compiled, down, env, inspire, migrate, migrate:install, up, and optimize commands. If you would like to allow more commands you may add them to the commands array in your tinker.php configuration file:
๐ŸŒ
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 - The in_array() function in PHP checks if a specific value exists in an array. It returns `true` if the value is found and `false` otherwise.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ find-second-largest-element-array
Second Largest Element in an Array - GeeksforGeeks
Given an array of positive integers arr[] of size n, the task is to find second largest distinct element in the array.
Published ย  February 10, 2025
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_arrays.asp
Python Arrays
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
๐ŸŒ
Reddit
reddit.com โ€บ r/php โ€บ how to check if array contains a specific word in php
r/PHP on Reddit: How to check if Array Contains a Specific Word in PHP
April 11, 2017 - array_flip is in O(n), explode is in O(n). If you don't reuse the created list, no benefit. Also for some reason, the topic started using an array and you basculed to a string ? ... PHP Code Golf: Detect if string contains an element from array.
๐ŸŒ
Laravel
laravel.com โ€บ docs โ€บ 12.x โ€บ eloquent
Eloquent: Getting Started | Laravel 12.x - The clean stack for Artisans and agents
As we have seen, Eloquent methods like all and get retrieve multiple records from the database. However, these methods don't return a plain PHP array.
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_arrays_add.asp
PHP Add Array Items
Arrays Indexed Arrays Associative Arrays Create Arrays Access Array Items Update Array Items Add Array Items Remove Array Items Sorting Arrays Multidimensional Arrays Array Functions PHP Superglobals
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ php-in_array-function
PHP in_array() Function - GeeksforGeeks
June 2, 2025 - The PHP in_array() function is a straightforward and handy tool for checking if a value exists within an array. Its flexibility with the optional strict type checking and compatibility with various data types make it a staple in PHP programming.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ includes
Array.prototype.includes() - JavaScript | MDN
The includes() method of Array instances determines whether an array includes a certain value among its entries, returning true or false as appropriate.