PHP - 检查是否数组索引存在或为空 [英] PHP - Checking if array index exist or is null
问题描述
有没有一种方法来检查,如果数组索引的存在,或为空?使用isset()
不告诉你的索引是否不存在或者虽然存在但为空。
如果我做的:使用isset($数组[$指数])|| is_null($数组[$指数])
也不会因为工作,如果索引不存在is_null会崩溃。
Is there a way to check if an array index exists or is null?
isset()
doesn't tell you whether the index doesn't exist or exists but is null.
If I do : isset($array[$index]) || is_null($array[$index])
it won't work because if the index doesn't exist is_null will crash.
我如何检查此吗?也就是有没有办法只检查是否存在的东西,如果它被设置为空或不是不管?
How can I check this please? Also is there a way to check only if something exist, no matter if it is set to null or not?
推荐答案
功能 array_key_exists()
能做到这一点,而 property_exists()
的对象,加什么Vineet1982说。感谢您的帮助。
The function array_key_exists()
can do that, and property_exists()
for objects, plus what Vineet1982 said. Thanks for your help.
这篇关于PHP - 检查是否数组索引存在或为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!