Home  >  Article  >  Backend Development  >  PHP array introductory tutorial in_array() function

PHP array introductory tutorial in_array() function

WBOY
WBOYOriginal
2016-07-25 08:57:501064browse
This article introduces the usage of the in_array() function of the PHP array function. Friends in need can refer to it.

In the php array function, the in_array() function searches for a specific value in an array and returns true if the value is found, otherwise it returns false.

The form is as follows: boolean in_array(mixed needle,array haystack[,boolean strict]);

Example, find whether the variable apple is already in the array, if so, output a piece of information:

<?php
//in_array用法举例
//by bbs.it-home.org
$fruit = "apple";   
$fruits = array("apple","banana","orange","pear");   
if( in_array($fruit,$fruits) )
echo "$fruit 已经在数组中";  
?>

Instructions: The third argument is optional and forces in_array() to consider types when searching.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn