<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>
查看$arr1中有没有叫'name'的键名。
也可以检查 数字索引。