Home  >  Article  >  Backend Development  >  Use of in_array() function in PHP

Use of in_array() function in PHP

WBOY
WBOYforward
2023-08-26 19:45:02741browse

in_array() 函数在 PHP 中的使用

in_array() function checks whether the specified value exists in the array.

Syntax

in_array(find, arr, type)

Parameters

  • find - The value to search for

  • arr - The array to search

  • type - The pattern to perform the search on. If this parameter is set to TRUE, it will look for the search string and specific type in the array.

Return

in_array()The function returns TRUE if the value is found in the array, otherwise it returns FALSE.

Example

The following is an example-

Real-time demonstration

<?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’s see another example-

Live Demonstration

<?php
$pro = array("Tom", "Amit", "Peter", "Rahul", 5, 10);
if (in_array(5, $pro, TRUE)) {
   echo "Match!";
} else {
   echo "No Match!";
}
?>

Output

Here is the output-

Match!

The above is the detailed content of Use of in_array() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete