The usage of in_array() in php is: [in_array(search, array)], where search specifies the value to be searched in the array, and array specifies the array to be searched. The in_array() function is used to search whether the specified value exists in the array.
The operating environment of this article: windows10 system, php7, thinkpad t480 computer.
We all know that there are a large number of built-in functions in PHP, which are very convenient to use in many situations. There is a function in_array(), and many friends may not know its specific usage. Let's take a look at what this function does.
The in_array() function is used to search whether the specified value exists in the array, and returns true if the given value exists in the array. At the same time, the function can also set a third parameter. If the third parameter is set to true, the function will only return true if the element exists in the array and the data type is the same as the given value. If the parameter is not found in the array, the function returns false.
Let’s take a look at the specific syntax and parameters:
in_array(search,array,type)
search Required. Specifies the value to search for in the array.
array Required. Specifies the array to search.
#type Optional. If this parameter is set to true, it is checked whether the type of the searched data and the value of the array are the same.
Finally let’s take a look at how to use this function. The following is the specific code:
<?php $people = array("Bill", "Steve", "Mark", "David"); if (in_array("23", $people, TRUE)) { echo "匹配已找到<br>"; } else { echo "匹配未找到<br>"; } if (in_array("Mark",$people, TRUE)) { echo "匹配已找到<br>"; } else { echo "匹配未找到<br>"; } if (in_array(23,$people, TRUE)) { echo "匹配已找到<br>"; } else { echo "匹配未找到<br>"; } ?>
Recommended learning: php training
The above is the detailed content of What is the usage of in_array() in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor
