我目前正在使用以下内容:
$a = array('foo' => 'bar', 'bar' => 'foo');
if(isset($a['foo']) && isset($a['bar'])){
echo 'all exist';
}
Run Code Online (Sandbox Code Playgroud)
然而,我将有以上几种数组键foo和bar我必须检查.检查每个必需的密钥是否比isset为每个必需的条目添加更有效的方法?
Bar*_*mar 23
您可以在一次isset()通话中将它们组合在一起:
if (isset($a['foo'], $a['bar']) {
echo 'all exist';
}
Run Code Online (Sandbox Code Playgroud)
如果您拥有所需的所有密钥数组,则可以执行以下操作:
if (count(array_diff($required_keys, array_keys($a))) == 0) {
echo 'all exist';
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5942 次 |
| 最近记录: |