<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>
Überprüfen Sie, ob in $arr1 ein Schlüssel mit dem Namen „name“ vorhanden ist.
Sie können auch den numerischen Index überprüfen.