我正在编写一个用于检查mgt模块的PHP代码,我需要给出试用,退出,缺陷或信誉良好的学生数量,这是在我计算出之前的cgpa,累积cgpa以及if学生们是否继续学习课程。所有这些都在for循环中,我想从for循环中得到结果。我怎么做。我的代码长度低于
我已经编辑了代码,我想要实现的目标可以被理解
foreach($aitemn as $item) {
if ( substr($item,1,2) < 13 || (substr($item,1,2) == 13 && $mode == '2')) {
if ($pcgpa < 1.0 && $gpa < 1.0 && $xlevel == 1) {
$remark = 'Probation';
$p = $p + 1;
}
elseif ($pcgpa < 1.0 && $gpa < 1.0 && $xlevel != 1) {
$remark = 'Withdraw';
$w = $w + 1;
}
elseif($gpa > 1.0 && $fc == 'NIL') {
$remark = 'In Good Standing';
$gs = $gs + 1;
}
elseif ( $gpa < 1.0 && $pcgpa > 1.0) {
$remark = 'Probation';
$p = $p + 1;
}
elseif ($fc <> 'NIL' ) {
$remark = 'Deficient';
$d = $d + 1;
}
}
elseif (substr($item,1,2) > 12) {
if ($pcgpa < 1.5 && $gpa < 1.5 && $xlevel == 1) {
$remark = 'Probation';
$p = $p + 1;
}
elseif ($pcgpa < 1.5 && $gpa < 1.5 && $xlevel != 1) {
$remark = 'Withdraw';
$w = $w + 1;
}
elseif($gpa > 1.5 && $fc == 'NIL') {
$remark = 'In Good Standing';
$gs = $gs + 1;
}
elseif ( $gpa < 1.5 && $pcgpa > 1.5) {
$remark = 'Probation';
$p = $p + 1;
}
elseif ($fc <> 'NIL' ) {
$remark = 'Deficient';
$d = $d + 1;
}
}
$num = $num + 1;
}
<td>Number in Good Standing: <?php echo $gs;?></br>
<td>Number on Probation: <?php echo $p;?></br>
<td>Number in Deficient <?php echo $d;?></br>
<td>Number in Withdrawn <?php echo $w;?></br>
答案 0 :(得分:0)
好的,我想我明白你的意思。
为了让您访问foreach
循环中的变量,一种方法是让您在循环中嵌套标记,如下所示:
<?php
foreach( $aitemn as $item ) {
// your other codes
?>
<td>Number in Good Standing: <?php echo $gs;?></br>
<td>Number on Probation: <?php echo $p;?></br>
<td>Number in Deficient <?php echo $d;?></br>
<td>Number in Withdrawn <?php echo $w;?></br>
<?php
} // close the foreach after the markup
?>
希望有所帮助。