如何检查数组值是否存在? [英] How to check if an array value exists?
本文介绍了如何检查数组值是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查 $something['say']
是否具有 'bla'
或 'omg'
的值?>
How can I check if $something['say']
has the value of 'bla'
or 'omg'
?
$something = array('say' => 'bla', 'say' => 'omg');
推荐答案
使用指令 if
?
if(isset($something['say']) && $something['say'] === 'bla') {
// do something
}
顺便说一下,您使用 say
键为一个值赋值了两次,因此您的数组将生成一个只有一个值的数组.
By the way, you are assigning a value with the key say
twice, hence your array will result in an array with only one value.
这篇关于如何检查数组值是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文