Home > Backend Development > PHP Tutorial > The difference between php isset and array_key_exists to check whether a certain value exists in the array

The difference between php isset and array_key_exists to check whether a certain value exists in the array

WBOY
Release: 2016-07-29 08:56:47
Original
1214 people have browsed it

Original address: http://ivhong.com/?p=110 (ivhong.com is the main address of my blog)

First take a look at the following code. What do you think the result is?

//定义一个数组, > 5.4
$arr = ['a' => null];
var_dump(isset($arr), array_key_exists('a', $arr));
Copy after login


---------------------Here are the results---------------------- -------

/*
 * 输出
 *bool(false)
 *bool(true)
 */

//isset 的用法是: 检测变量是否设置,并且不是 NULL。所以会有上面的输出
//如果判断数组中是否存在某个键值,还是乖乖的用 array_key_exists 吧,不然就是给自己挖了一个巨隐藏的坑啊!!!
Copy after login

The above introduces the difference between php isset and array_key_exists to check whether a certain value exists in the array, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template