


A brief discussion on PHP's in_array function to check whether a certain value exists in an array, a brief discussion on in_array
A brief talk about the in_array function in PHP to check whether a certain value exists in the array, a brief talk about in_array
PHP in_array() function checks whether a certain value exists in the array, and returns if it exists TRUE, otherwise returns FALSE.
Syntax:
bool in_array( mixed needle, array array [, bool strict] )
Parameter description:
参数 | 说明 |
---|---|
needle | 需要在数组中搜索的值,如果是字符串,则区分大小写 |
array | 需要检索的数组 |
strict | 可选,如果设置为 TRUE ,则还会对 needle 与 array 中的值类型进行检查 |
Example:
<?php $arr_a = array("a", "b", "c", 1); if(in_array("a", $arr_a)){ echo '字符 a 在 $arr_a 数组中存在'; } else { echo '字符 a 在 $arr_a 数组中不存在'; } ?>
The example output results are as follows:
Example of strict check for character a in $arr_a array:
<?php $arr_a = array("a", "b", "c", 1); if(in_array("1", $arr_a, TRUE)){ echo '字符 1 在 $arr_a 数组中存在'; } else { echo '字符 1 在 $arr_a 数组中不存在'; } ?>
The example output results are as follows:
Character 1 does not exist in the $arr_a array. Example of array as needle:
<?php $arr_a = array(array("a", "b"), 1, 2); $arr_b = array("a", "b"); if(in_array($arr_b, $arr_a)){ echo '数组 $arr_b 在 $arr_a 数组中存在'; } else { echo '数组 $arr_b 在 $arr_a 数组中不存在'; } ?>
The example output results are as follows:
Array $arr_b exists in array $arr_a
The above article briefly talks about PHP checking whether a certain value exists in the array. The in_array function is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Bangkejia.

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

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