array_search()
regantewksbury12 total contributions
Published Sep 8, 2023
Contribute to Docs
The array_search()
function searches an array for a given value and returns the first matching key for that value.
Syntax
array_search(value, array, strict)
value
: The value to search for.array
: Thearray
to search in.strict
: Optional argument that defaults tofalse
if not given. When set totrue
, the function will search for identical elements to the value. For example, a strict search for an integer will not match a string version of that integer.
Note: String values are case-sensitive for this function.
Example
In this example, the h
key is returned using the array_search()
method.
<?php$a = array("a"=>"andrew","b"=>"byrne","h"=>"hozier");echo array_search("hozier",$a);?>
The output looks like this:
h
Codebyte Example
The following codebyte example can be run and uses the array_search()
method.
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.