相关疑难解决方法(0)

什么是更快更好地确定PHP中是否存在数组键?

考虑这两个例子......

$key = 'jim';

// example 1
if (isset($array[$key])) {
    // ...
}

// example 2    
if (array_key_exists($key, $array)) {
    // ...
}
Run Code Online (Sandbox Code Playgroud)

我很想知道其中任何一个是否更好.我一直使用第一个,但看到很多人在这个网站上使用第二个例子.

那么哪个更好?快点?更明确的意图?

php performance

147
推荐指数
6
解决办法
7万
查看次数

如何检查是否存在多个数组键

我有各种各样的数组,将包含

story & message
Run Code Online (Sandbox Code Playgroud)

or just

story
Run Code Online (Sandbox Code Playgroud)

How would I check to see if an array contains both story and message? array_key_exists() only looks for that single key in the array.

Is there a way to do this?

php key

75
推荐指数
6
解决办法
9万
查看次数

检查是否存在所有多个PHP数组键

我目前正在使用以下内容:

    $a = array('foo' => 'bar', 'bar' => 'foo');

    if(isset($a['foo']) && isset($a['bar'])){
      echo 'all exist';
    }
Run Code Online (Sandbox Code Playgroud)

然而,我将有以上几种数组键foobar我必须检查.检查每个必需的密钥是否比isset为每个必需的条目添加更有效的方法?

php arrays

8
推荐指数
1
解决办法
5942
查看次数

标签 统计

php ×3

arrays ×1

key ×1

performance ×1