PHP in_array array function

Last Updated: February 20, 2022

in_array – Check value exists in array

Syntax

in_array(mixed $needle, array $haystack, bool $strict = false): bool

Supports (PHP 4 , PHP 5, PHP 7, PHP 8)

Parameters

Parameter Description
needle Searched value
haystack target array

Return Value

Return true if the searched value is found otherwise it will return false

Example


$my_array = array("a" => "One","b" => "Two", "c" => "Three");
if (in_array("Two", $my_array)) {
    echo "Got Two";
}

Output

Got Two
Test