for loop - How can I echo the third condition in this php IF STATEMENT? -
i have developed school mark-sheet application using phpmysql. in mark-sheet, if student fails in 1 of subjects, he/she declared 'failed' in result section of mark-sheet. job code.
today principal of school has come me , said not in use today, , told me change code like: if student fails in 2 subjects, should declared 'failed', if fails in 1 subject, echo
'simple`, , if passes in subjects, should declared 'passed'. have been spending long hours trying figure out how modify code still not come solution. so, come here asking help. suggestion warmly welcome. lot in advance. here code:
<?php $all = array(41, 55, 56, 39, 29, 47); //mark in each subject. pass mark 30 // second, iterate on them till find 1 value -30 for($i=0; $i < count($all); $i++){ if($all[$i] < 30) $sum = 1; } echo (!empty($sum)) ? 'failed' : 'passed';//'simple' must included here, still not find solution. ?>
just create counter know number of failatures , use conditions different prints.
<?php $all = array(41, 55, 56, 39, 29, 47); //mark in each subject. pass mark 30 $numfails = 0; // second, iterate on them till find 1 value -30 for($i=0; $i < count($all); $i++){ if($all[$i] < 30){ $numfails++; //incrementing number of failatures } } if($numfails > 1){ echo "failed"; } else if($numfails == 1){ echo "simple"; } else{ echo "passed"; } ?>
try write code. clear , easy read possible.
also name variables meaning.
Comments
Post a Comment