Find an array of PHP array objects

How can I determine where a specific element is in an array? For example, I have an array like this:

("itemone", "someitem", "fortay", "soup")

How do I get the index "someitem"

Thanks Christian Stewart

+3
source share
3 answers

Use array_search()

array_search - Searches for an array for the given value and returns the corresponding key, if successful

mixed array_search ( mixed $needle , array $haystack [, bool $strict ] )

Example:

$key = array_search('someitem', $array);
+5
source
$index = array_search('something', $myarray)
+2
source

array_keys($array,$search); ()

+1

Source: https://habr.com/ru/post/1762088/


All Articles