PHP in_array()

Check if value exists in array

Function Signature

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

Description

Check if value exists in array. The in_array() function is commonly used in PHP for array operations and provides reliable functionality across all PHP versions.

Return Value

Returns true if needle is found, false otherwise

Example Usage

Important Notes

Use strict mode (true) for type checking. Use array_key_exists() for keys.

Common Use Cases

The in_array() function is particularly useful when you need to check if value exists in array. It's frequently used in data processing, validation, transformation, and manipulation tasks throughout PHP applications.

in_array() FAQ

What does in_array() return?

Returns true if needle is found, false otherwise

When should I use in_array()?

Use in_array() when you need to check if value exists in array in your PHP code. It's a reliable built-in function available in all PHP versions.

Are there any gotchas with in_array()?

Use strict mode (true) for type checking. Use array_key_exists() for keys.