Php 这个foreach应该被称为获取未定义的索引吗
我在下面有一个关联数组:Php 这个foreach应该被称为获取未定义的索引吗,php,Php,我在下面有一个关联数组: $questions = array(); while ($selectedstudentanswerstmt->fetch()) { $questions[$detailsStudentId][$detailsQuestionId] = array( 'questionno'=>$detailsQuestionNo, 'content'=>$detailsQuestionContent
$questions = array();
while ($selectedstudentanswerstmt->fetch()) {
$questions[$detailsStudentId][$detailsQuestionId] = array(
'questionno'=>$detailsQuestionNo,
'content'=>$detailsQuestionContent
);
}
现在我想在这里的for each循环中显示信息,但我的问题是foreach循环应该被调用什么,因为我认为下面的说法是不正确的,因为它一直说questionno
,而content
在循环中未定义:
var_dump($questions);
foreach ($questions as $questionId => $question) {
//LINE 571
echo '<p><strong>Question:</strong> ' .htmlspecialchars($question['questionno']). ': ' .htmlspecialchars($question['content']) . '</p>' . PHP_EOL;
}
Notice: Undefined index: questionno in ... on line 571
Notice: Undefined index: content in ... on line 571
var_dump($questions);
foreach($questionId=>$question的问题){
//第571行
回声“问题:”.htmlspecialchars($Question['questionno']):“.htmlspecialchars($Question['content'])。”.PHP\EOL;
}
注意:未定义索引:问题号在。。。在线571
注意:未定义索引:内容在。。。在线571
在关联索引生效之前,有两个维度。因此,您需要在其中嵌套另一个foreach循环:
foreach ($questions as $stundentId => $student)
{
foreach ($student as $questionId => $question)
{
// ...
}
}
认真地你甚至懒得看你的数据结构吗?
foreach ($questions as $stundentId => $student)
{
foreach ($student as $questionId => $question)
{
// ...
}
}