PHPize Online / SQLize Online

Popular

array_search

Tags: PHP 5.x PHP 7.x PHP 8.x

array_search — Searches the array for a given value and returns the first corresponding key if successful.

Description

array_search(
    mixed $needle,
array $haystack,
bool $strict = false
): int|string|false
Searches for needle in haystack.

Parameters

needle
The searched value.
haystack
The array.
strict
If the third parameter strict is set to true then the array_search() function will search for identical elements in the haystack. This means it will also perform a strict type comparison of the needle in the haystack, and objects must be the same instance.

Return Values

Returns the key for needle if it is found in the array, false otherwise.

array_search - New snippets