Logical operators equation in php -


i have problem function should combine logical operators according data in array:

$arr = array(     0 => array(false, "or"),     1 => array(false, "or"),     2 => array(true) ); 

the equation should be:

  • false or false or true
  • ($arr[0][0] $arr[0][1] $arr[1][0] $arr[1][1] $arr[2][0])

and result: true

but wrong happens in function , returns false. missing?

var_dump( arrayboolvalidation($arr) );  function arrayboolvalidation (array $arr) {     $num = count($arr);     $status = $arr[0][0];     for($i = 1; $i < $num; ++$i) {         if ($arr[$i-1][1] == "and") {             $status = filter_var($status, filter_validate_boolean) , filter_var($arr[$i][0], filter_validate_boolean);         } else if ($arr[$i-1][1] == "or") {             $status = filter_var($status, filter_validate_boolean) or filter_var($arr[$i][0], filter_validate_boolean);         }     }     return $status; } 

it's operator precedence issue. and not same &&. @ http://php.net/manual/en/language.operators.precedence.php

= has higher priority and, $a = $b , $c; equals $a = $b;.

you must use brackets ($a = ($b , $c);) or better use &&. same thing or (use ||).


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -