PHP checks whether a value of in_array function _ php instance exists in the array

Source: Internet
Author: User
The following is an article about checking whether an in_array function exists in an array in PHP. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the PHP in_array () function to check whether a value exists in the array. If yes, TRUE is returned; otherwise, FALSE is returned.

Syntax:

bool in_array( mixed needle, array array [, bool strict] )

Parameter description:

Parameters Description
Needle The value to be searched in the array. if it is a string, it is case sensitive.
Array Array to be retrieved
Strict Optional. If this parameter is set to TRUE, the needle and array value types are checked.

Example:

<? Php $ arr_a = array ("a", "B", "c", 1); if (in_array ("a", $ arr_a )) {echo 'character a exists in the $ arr_a array';} else {echo 'character a does not exist in the $ arr_a array';}?>

The output result is as follows:

For example, if character a is strictly checked in the $ arr_a array:

<? Php $ arr_a = array ("a", "B", "c", 1); if (in_array ("1", $ arr_a, TRUE )) {echo 'character 1 exists in the $ arr_a array';} else {echo 'character 1 does not exist in the $ arr_a array';}?>

The output result is as follows:

Character 1 does not exist in the $ arr_a array as a needle example:

<? Php $ arr_a = array ("a", "B"), 1, 2); $ arr_ B = array ("a", "B "); if (in_array ($ arr_ B, $ arr_a) {echo 'array $ arr_ B exists in $ arr_a array ';} else {echo 'array $ arr_ B does not exist in $ arr_a array';}?>

The output result is as follows:

Array $ arr_ B exists in the $ arr_a array

The above discussion about whether the in_array function exists in the PHP check array is all the content shared by the editor. I hope you can give us a reference and support for your feet.

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.