Detailed explanation of the steps for array_search() function to return key names by element value

php中世界最好的语言
Release: 2023-03-27 07:00:02
Original
2043 people have browsed it

This time I will bring youarray_search() function to return the key name by element value in detail. What are theprecautionsfor the array_search() function to return the key name by element value? The following is a practical case, let’s take a look. The

array_search() function is the same asin_array(), which searches for a key value in an array.
If the value is found, the key name of the matching element will be returned. If not found, false is returned

array_search() definition and usage
array_search() function is the same as in_array(), searching for a key value in the array. If the value is found, the key of the matching element is returned. If not found, returns false.

Prior to PHP 4.2.0, functions returned null instead of false on failure.

If the third parameter strict is specified as true, the key name of the corresponding element will only be returned if thedata typeand value are consistent.

Syntax
array_search(value,array,strict)Parameter Description
value Required. Specifies thesearch for thevalue in the array.
array required. The array to be searched.
strict Optional. Possible values:

true
false - Default
If the value is set to true, the type of the given value will also be checked in the array. (See Example 2)

php arrayExample of function array_search:

"Dog","b"=>"Cat","c"=>"Horse"); echo array_search("Dog",$a); ?>
Copy after login

Output:
a

I believe I read the case in this article You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the steps to create scheduled tasks through the yii framework through console commands

PHP accelerator eAccelerator configuration and usage steps Detailed explanation

The above is the detailed content of Detailed explanation of the steps for array_search() function to return key names by element value. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!