After finishing a script for one of my clients I noticed an irregularity with the way PHP processes posted data using checkbox fields. if you do the following check; if(!$_POST['checkbox1']=='On'){ return true; } PHP: it will return false whether or not the value is 'on' or 'On' if you do the following check; if($_POST['checkbox2']=='on'){ return true; } PHP: it will only return true if you use lower case 'on' Anyone else noticed this before?
About "strange" behaviour of the first example. ! (not) operator has higher priority than == (comparison) operator, so the PHP interpreter firstly calculates !$_POST['checkbox1'] and after that it compares resulting value with 'On'. To avoid this "strange" behaviour use parentheses. So your code could be rewritten as: if(!($_POST['checkbox1']=='On')) { return true; } PHP: For more information see Operator Precedence
I understand operator precedence but I just thought it was unusual that it would accept "On" as "on" when comparing for the negated version. The operator precedence has no correlation to the values I'm passing into the conditions. Of course the default value for checkboxes is always lower case "on" so I was in error to insert them as "On" in the first place. Just thought it was strange that it would give me 2 different results.