尝试输出变量的更新值时出现 PHP 数组到字符串的转换错误


PHP Array to string conversion error when trying to output updated value for a variable

目前,我的代码输出一个名称,当前存储在SQL数据库中的出勤情况,以及旁边的文本框,可以在其中更改出勤值。

由于输出了多个名称,因此我在末尾有一个提交按钮,以便可以同时提交所有值。 为了检查是否为每个用户提交了新的更改值,我有一个由 (a) 指示的 echo 语句。
提交按钮后,它应显示已提交的出席的名称和新值。
但是,一旦按下提交按钮,它就会显示:第 (a) 行上的数组到字符串转换错误。 我将不胜感激任何人对我如何解决这个问题的任何想法(提前感谢您)。
//Here I have my SQL Statement (it's long so I haven't included it)  
$rownumber = $sqlquery->num_rows;
while($row7 = mysqli_fetch_array($sqlquery, MYSQLI_ASSOC)){
  echo $row7['FirstName'] . ' ' . $row7['LastName'] . ' "'  . $row7['LessonAtt'] . '"' ;
  $firstnameLabel = $row7['FirstName'];
  $lastNameLabel = $row7['LastName'];       
  $attLabel = $row7['LessonAtt'];
  $lessonID = $row7['LessonID'];  
  $error = '';
  echo <<<_END
    <form method='post' action='homepageInstructor.php?view=$user'>$error
    <span class='fieldname'>
    <input type ="text"  name='attendance[]' value=$attLabel>
_END;
  echo '<br>';
  if (isset($_POST['attendance'])) 
  {
      $attLabel = $_POST['attendance'];
     (a) echo $firstnameLabel .  $attLabel  . ' ';
  }
}

这是print_r($_POST['出勤'])完成时的结果

因为表单项的名称末尾有 [],所以最终会得到一个数组:

<input type ="text"  name='attendance[]' value=$attLabel>

那个蜜蜂说,要访问它的值,你应该这样做:

$_POST['attendance'][0] // First occurence of the attendance field
$_POST['attendance'][1] // Second occurence of the attendance field
...

问候