Home > php教程 > php手册 > body text

Commonly used array functions in php (4) (whether there is a certain key name or index in the array)

WBOY
Release: 2016-10-28 15:03:32
Original
1205 people have browsed it
<span style="color: #008000">/*</span><span style="color: #008000">**********array_key_exists(检查键名或索引是否在数组中)****************</span><span style="color: #008000">*/</span>
<span style="color: #800080">$arr1</span> = <span style="color: #0000ff">array</span>('name' => 'Sheldon', 'age' => 30, 'address' => 'Carlifornia'<span style="color: #000000">);
</span><span style="color: #0000ff">if</span> (<span style="color: #008080">array_key_exists</span>('name', <span style="color: #800080">$arr1</span><span style="color: #000000">)) {
    </span><span style="color: #0000ff">echo</span> 'the name element is in the array.'<span style="color: #000000">;
} </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
    </span><span style="color: #0000ff">echo</span> 'name elment not exist.'<span style="color: #000000">;
}</span>
Copy after login

Check if there is a key named 'name' in $arr1.

Also check the numerical index.

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