echo
的{p> $res
: -
stdClass Object ( [permissionId] => 23 [roleId] => 14 [view] => 0 [add] => 0 [edit] => 0 [deleteRole] => 0 [status] => 1 [moduleId] => 1 )
我尝试了下面的内容
if($res->view = 1 or $res->add = 1 or $res->edit = 1 or $res->deleteRole = 1 ){
echo "condition true";
} else {
echo "condition false";
}
但它总是回应条件真实。如果条件合适吗?如果有条件,请帮我写一下。
答案 0 :(得分:3)
更改为==
比较运算符,如果将=
始终设为true,则赋值运算符始终返回true
答案 1 :(得分:2)
其实你不是在比较,你只是在做任务。 =
用于分配而不是用于比较。
因此请使用==
代替=
if($res->view == 1 or $res->add == 1 or $res->edit == 1 or $res->deleteRole == 1 ){
echo "condition true";
} else {
echo "condition false";
}
OR
if($res->view == 1 || $res->add == 1 || $res->edit == 1 || $res->deleteRole == 1 ){
echo "condition true";
} else {
echo "condition false";
}
注意: - 让您了解自己想要比较的内容以及以何种方式进行比较。因此,相应地调整代码。谢谢
答案 2 :(得分:1)
给出==(比较运算符)而不是=(赋值运算符)和||
if(($res->view == 1) || ($res->add == 1) || ($res->edit == 1) || ($res->deleteRole == 1) ){
echo "condition true";
} else {
echo "condition false";
}