- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
in_array() function in PHP
The in_array() function checks if a specified value exists in an array.
Syntax
in_array(find, arr, type)
Parameters
find − The value to be searched
arr − The array to search
type − The mode in which the search is to be performed. If the parameter is set to TRUE, then it looks for for the search string and specific type in the array.
Return
The in_array() function returns TRUE if the value is found in the array, or FALSE otherwise.
Example
The following is an example −
<?php $stu = array("Tom", "Amit", "Peter", "Rahul"); if (in_array("Amit", $stu)) { echo "Match!"; } else { echo "No Match!"; } ?>
Output
The following is the output −
Match!
Example
Let us see another example −
<?php $pro = array("Tom", "Amit", "Peter", "Rahul", 5, 10); if (in_array(5, $pro, TRUE)) { echo "Match!"; } else { echo "No Match!"; } ?>
Output
The following is the output −
Match!
Advertisements