Php in_array function

Source: Internet
Author: User

 

In_array
(PHP 4 and PHP 5)

In_array-check whether an array of values exists

Description
Boolean in_array (mixed $ needle, array $ heexke [, Boolean $ strict])
Search for the needle of heatake.

Parameters

Needle
The value to be searched.

Note: If the needle is a string, such comparison is case sensitive.


Heatake
Array.

Strict
If the strict third parameter is set to TRUE, the in_array () function will also check all kinds of needles in the haystack.


Return value
Returns TRUE, except for false, if found in the needle array.

Modify

Version description
4.2.0 needles may now be an array.


Instance

Example 1
<? Php
$ People = array ("Peter", "Joe", "Glenn", "Cleveland ");

If (in_array ("Glenn", $ people ))
  {
Echo "Match found ";
  }
Else
  {
Echo "Match not found ";
  }
?>
Output:
Match found
Example 2
<? Php
$ People = array ("Peter", "Joe", "Glenn", "Cleveland", 23 );

If (in_array ("23", $ people, TRUE ))
  {
Echo "Match found <br/> ";
  }
Else
  {
Echo "Match not found <br/> ";
} If (in_array ("Glenn", $ people, TRUE ))
  {
Echo "Match found <br/> ";
  }
Else
  {
Echo "Match not found <br/> ";
} If (in_array (23, $ people, TRUE ))
  {
Echo "Match found <br/> ";
  }
Else
  {
Echo "Match not found <br/> ";
  }
?>
Output:
Match not found
Match found
Match found

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.