PHP array introductory tutorial in_array() function

WBOY
Release: 2016-07-25 08:57:50
Original
1109 people have browsed it
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 已经在数组中";  
?>
Copy after login

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



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template