[英]problems with php in_array
Hey guys got an issue with the in_array not returning true. 大家好,in_array没有返回true。
my code is as follows: 我的代码如下:
if ( in_array( 'item_name', $this->conditions ) ) {
print "test";
}
this is just a test code. 这只是一个测试代码。 the $this->conditions is set in someplace else in the files and it looks like this:
$ this-> conditions是在文件的其他地方设置的,看起来像这样:
Array
(
[0] => Array
(
[operator] =>
[property] => item_name
[logic] => contains
[value] => the age
)
)
its not printing the "test"; 它不打印“测试”; what am i doing wrong ?
我究竟做错了什么 ?
var_dump added below: var_dump添加如下:
array (size=2)
0 =>
array (size=4)
'operator' => string '' (length=0)
'property' => string 'item_name' (length=9)
'logic' => string 'contains' (length=8)
'value' => string 'the age' (length=7)
1 =>
array (size=4)
'operator' => string 'or' (length=2)
'property' => string 'item_name' (length=9)
'logic' => string 'ends' (length=4)
'value' => string 'malouf' (length=6)
You have a nested array. 您有一个嵌套数组。 Try this :
尝试这个 :
foreach ($this->conditions as $arr) {
if ( in_array( 'item_name', $arr ) ) {
print "test";
}
}
please try this 请尝试这个
foreach($this->conditions as $condition){
if(in_array( 'item_name', $condition))
echo 'test';
};
I hope this will help you 我希望这能帮到您
in_array — Checks if a value exists in an array
in_array()
wont return true because there is no value "item_name"
. in_array()
不会返回true,因为没有值"item_name"
。 You have to extract the inner array first. 您必须先提取内部数组。 This :
in_array( 'item_name', $this->conditions[0])
will return true
这:
in_array( 'item_name', $this->conditions[0])
将返回true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.