PHP Array function sequence In_array () find out if an array value exists _php tutorial

Source: Internet
Author: User
In_array () Definition and usage
The In_array () function searches the array for the given value.

Grammar
In_array (Value,array,type)
Parameter description
Value is required. Specifies the value to search for in the array.
Array required. Specifies the array to search for.
Type is optional. If set to true, checks whether the searched data is the same as the type of the array's value.

Description
Returns true if the given value exists in an array of arrays. If the third argument is set to True, the function returns true only if the element exists in the array and the data type is the same as the given value.

If no arguments are found in the array, the function returns FALSE.

Note: If the value parameter is a string and the type parameter is set to True, the search is case-sensitive.

Example 1
Copy CodeThe code is as follows:
$people = Array ("Peter", "Joe", "Glenn", "Cleveland");

if (In_array ("Glenn", $people))
{
echo "Match found";
}
Else
{
echo "Match not Found";
}
?>

Output:

Match found
Example 2
Copy CodeThe code is as follows:
$people = Array ("Peter", "Joe", "Glenn", "Cleveland", 23);

if (In_array ("@", $people, TRUE))
{
echo "Match found
";
}
Else
{
echo "Match not found
";
}if (In_array ("Glenn", $people, TRUE))
{
echo "Match found
";
}
Else
{
echo "Match not found
";
}if (In_array ($people, TRUE))
{
echo "Match found
";
}
Else
{
echo "Match not found
";
}
?>

Output:

Match not found
Match found
Match found

http://www.bkjia.com/PHPjc/324486.html www.bkjia.com true http://www.bkjia.com/PHPjc/324486.html techarticle In_array () defines and uses the In_array () function to search the array for the given value. The syntax In_array (value,array,type) parameter describes the value required. Specifies the value to search for in the array. Array must ...

  • 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.