validation - Problem with Boolean Values in PHP -
validation - Problem with Boolean Values in PHP -
i've problems handling boolean values in php. validation script before storing info database. wrote global validator validate , homecoming boolean value whether validation successful . here code.
//validate $isvalid = true; foreach($team $key=>$val) { if(!is_array($val)){ $isvalid = $isvalid && validate($val, $key); } } for($it=0;$it<count($team['members']);$it++){ foreach($team['members'][$it] $key=>$val) { $isvalid = $isvalid && validate($val, $key); } } if(!$isvalid) { // edited: if(!isvalid) echo "validation error"; exit(1); } //end of validate the validate function working end getting $isvalid = true or other way, when seek test cases. hmm.. doing wrong here ?
please check, if form trick:
if( false === $isvalid) { echo "validation error"; exit(1); } note, ( ! $isvalid ) or (false == $isvalid ) in cases homecoming results, @ first wrong. see illustration hint in strpos() documentation.
in fact, results fine, since operations line ! or == seek cast operands in 'useful' way.
that said, it's improve user === operator, since checks values , types of operands. please see operator overview.
php validation boolean
Comments
Post a Comment