Php 使用计数有困难吗
您正在对作为问题编号的字符串调用Php 使用计数有困难吗,php,Php,您正在对作为问题编号的字符串调用count。为什么它不返回数组的计数会让您感到惊讶 Put$noofquestions=count($studentData['questions')。您正在调用count作为问题编号的字符串。为什么它不返回数组的计数会让您感到惊讶 Put$noofquestions=count($studentData['questions')在foreach循环之前。执行以下操作 <?php if($check) { echo '<p c
count
。为什么它不返回数组的计数会让您感到惊讶
Put
$noofquestions=count($studentData['questions')在foreach
循环之前执行code>。您正在调用count
作为问题编号的字符串。为什么它不返回数组的计数会让您感到惊讶
Put$noofquestions=count($studentData['questions')代码>在foreach循环之前。执行以下操作
<?php
if($check)
{
echo '<p class="green"><strong>Fully Correct</strong></p>';
}
else
{
echo '<p class="red"><strong>Not Correct / Not Fully Correct</strong></p>';
}
$count=0;
foreach($studentData['questions']作为$questionId=>$questionData)
{
$count+=1;
回显'.$questionData['questionno'].'':'.$questionData['content'.'';
}
echo$count;
执行以下操作
<?php
if($check)
{
echo '<p class="green"><strong>Fully Correct</strong></p>';
}
else
{
echo '<p class="red"><strong>Not Correct / Not Fully Correct</strong></p>';
}
$count=0;
foreach($studentData['questions']作为$questionId=>$questionData)
{
$count+=1;
回显'.$questionData['questionno'].'':'.$questionData['content'.'';
}
echo$count;
好的,我可以问一下如何找到正确和错误问题的数量吗?当三个问题中有两个不正确,一个正确时,它会显示为1。我可以问一下如何找到正确和错误问题的数量吗,当三个问题中有两个不正确,一个正确时,它会同时显示为1。请检查所有变量名。重新阅读foreach语法文档。我们可以看到$studentData中有三项,但您正在计算$questionData。请重新检查所有变量名称。重新阅读foreach语法文档。我们可以看到$studentData中有三项,但您正在计算$questionData。
<?php
if($check)
{
echo '<p class="green"><strong>Fully Correct</strong></p>';
}
else
{
echo '<p class="red"><strong>Not Correct / Not Fully Correct</strong></p>';
}
$count=0;
foreach ($studentData['questions'] as $questionId => $questionData)
{
$count += 1;
echo '<h3>'.$questionData['questionno'].': '.$questionData['content'].'</h3>';
}
echo $count;