PHP in_array() Function

The in_array() function checks if a value exists in an array. It returns true if the value is found, otherwise false.

Key Features of in_array()

Syntax of in_array()

Syntax

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

Example Using in_array()

The following example demonstrates how in_array() is used:

Example


$array = ["PHP", "JavaScript", "Python"];
if (in_array("JavaScript", $array)) {
    echo "JavaScript is in the array!";
} else {
    echo "JavaScript is not in the array.";
}
       

Output

JavaScript is in the array!