Home > php教程 > php手册 > Commonly used array functions in php (5) (getting a collection of key names in an array)

Commonly used array functions in php (5) (getting a collection of key names in an array)

WBOY
Release: 2016-10-28 15:03:31
Original
1179 people have browsed it

array_keys($arr, $search_value, $strict);

——Get the collection of key names in the array.

//Parameter 1: Array to be retrieved; Parameter 2: Key value to be retrieved. Default is NULL; Parameter 3: Whether to strictly compare (===), default is false. Parameter 3 was added in php5.0


<span style="color: #800080">$arr1</span> = <span style="color: #0000ff">array</span><span style="color: #000000">(
    </span>'a'=>'apple', 
    'b'=>'banana', 
    'f'=><span style="color: #0000ff">false</span>, 
    'b1'=><span style="color: #0000ff">false</span>, 
    'b2'=><span style="color: #0000ff">false</span>, 
    'b3'=>'false', 
    'b4'=><span style="color: #0000ff">true</span>,
    'num1'=>1, 
    'num2'=>'1'<span style="color: #000000">
);
</span><span style="color: #008000">//</span><span style="color: #008000">var_dump(array_keys($arr1, 'banana');</span>
<span style="color: #008080">var_dump</span>(<span style="color: #008080">array_keys</span>(<span style="color: #800080">$arr1</span>, 1, <span style="color: #0000ff">false</span>));
Copy after login

Output: array(3) { [0]=> string(2) "b4" [1]=> string(4) "num1" [2]=> string(4) "num2" }

There is no strict comparison. true at index 'b4' is also treated as 1.

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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template