2

echo of $res showing following result:-

stdClass Object ( [permissionId] => 23 [roleId] => 14 [view] => 0 [add] => 0 [edit] => 0 [deleteRole] => 0 [status] => 1 [moduleId] => 1 )

I have tried like something below

if($res->view = 1 or $res->add = 1 or $res->edit = 1 or $res->deleteRole = 1 ){ 
     echo "condition true";
} else {
     echo "condition false";
}

But it always echo condition true. Is if condition is right? Please help me how to write if condition.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Kevin
  • 653
  • 2
  • 13
  • 34
  • 2
    use this if($res->view == 1 or $res->add == 1 or $res->edit == 1 or $res->deleteRole == 1 ){ echo "condition true"; } else { echo "condition false"; } – Indresh Tayal Feb 13 '17 at 07:48

3 Answers3

3

change to == Comparison Operator, if you put = it always true, the assignment operator always return true

Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
2

Actually you are not comparing, you are just doing assignment. = used for assignment not for comparison.

So use == instead of =

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";
}

Note:- Rest it's up-to-you what you want to compare and in which manner. So adjust code accordingly.Thanks

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
1

Give == (Comparison operator) rather than = (Assignment operator) and ||

if(($res->view == 1) || ($res->add == 1) || ($res->edit == 1) || ($res->deleteRole == 1) ){ 
     echo "condition true";
} else {
     echo "condition false";
}
affaz
  • 1,191
  • 9
  • 23