<?php function test_case($a, $b, $c) { // Without Parenthesis if ($a || $b && $c) { $test1 = TRUE; } else { $test1 = FALSE; } // With Parenthesis if (($a || $b) && $c) { $test2 = TRUE; } else { $test2 = FALSE; } // Compare result if ($test1 !== $test2) { printf( 'Condition (%s || %s && %s) does NOT match ((%s || %s) && %s) --- Should have been "%s" but was actually "%s"'.PHP_EOL, strtoupper(var_export($a, TRUE)), strtoupper(var_export($b, TRUE)), strtoupper(var_export($c, TRUE)), strtoupper(var_export($a, TRUE)), strtoupper(var_export($b, TRUE)), strtoupper(var_export($c, TRUE)), strtoupper(var_export($test2, TRUE)), strtoupper(var_export($test1, TRUE)) ); } else { printf( 'Condition (%s || %s && %s) works as intended'.PHP_EOL, strtoupper(var_export($a, TRUE)), strtoupper(var_export($b, TRUE)), strtoupper(var_export($c, TRUE)) ); } } // Test all possible variations test_case(TRUE, TRUE, TRUE); test_case(TRUE, TRUE, FALSE); test_case(TRUE, FALSE, TRUE); test_case(TRUE, FALSE, FALSE); test_case(FALSE, TRUE, TRUE); test_case(FALSE, TRUE, FALSE); test_case(FALSE, FALSE, TRUE); test_case(FALSE, FALSE, FALSE);
You have javascript disabled. You will not be able to edit any code.