PHP - array_search
Trieda
Metóda - array_search
(PHP 4 >= 4.0.5, PHP 5, PHP 7)
Searches the array for a given element. We talk about the problem as about searching for a needle in a haystack.
Procedurálne
- function array_search (mixed $needle, array $haystack, bool $strict = false) : mixed
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $needle | mixed | A needle (a string to find). | |
| $haystack | array | A haystack (where to search). | |
| $strict | bool | false | The third optional parameter is a type of |
Mávratovej hodnoty
Vracia: mixed
A key under which a needle is found. It returns FALSE in the
case of failure. As the needle can be found on the position 0, the result must
be compared using ===. If invalid parameters are passed, it returns
NULL.
Príklady
<?php
$array = ['Homer', 'Marge', 'Bart', 'Lisa', 'Meggie'];
$key = array_search('Bart', $array);
echo $key;
Súvisiace manuály
- function array_keys (array $array, mixed $search_value = null, bool $strict = false) : array
- function array_key_exists (mixed $key, array $array) : bool
- function array_values (array $array) : array
- function in_array (mixed $needle, array $haystack, bool $strict = false) : bool
