Home >php教程 >php手册 >Commonly used array functions in php (4) (whether there is a certain key name or index in the array)

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

WBOY
WBOYOriginal
2016-10-28 15:03:321252browse
<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>

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

Also check the numerical index.

Statement:
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