“数组”在空表单字段中显示为错误

I'm trying to echo out errors from a form using arrays. i store the errors in an array, then I print_r. But when I omit some fields and submit the for I get the string "Array" showng up as an error.

below is the php code I'm working with...

<?php
    if (isset($_POST['submit'])) { 
      $error = array();
      if (empty($_POST['request'])) { $error .= "<li>Prayer Request is Empty</li>";}
      if (empty($_POST['phone']))   { $error .= "<li>Please enter a valid phone Number</li>";}
      if (empty($_POST['response'])){ $error .= "<li>Please choose a way to contact you.</li>";}
      ?>
          <div class='Errors' >
          <?php print_r ($error); ?>
          </div>

Well what did you expect with $error = array()?

Try $error = ""; instead.

Try changing the .= to [] =

<?php
  if (isset($_POST['submit'])) { 
  $error = array();
  if (empty($_POST['request'])) { $error[] = "<li>Prayer Request is Empty</li>";}
  if (empty($_POST['phone']))   { $error[] = "<li>Please enter a valid phone Number</li>";}
  if (empty($_POST['response'])){ $error[] = "<li>Please choose a way to contact you.</li>";}
?>
<div class='Errors' >
<?php print_r ($error); ?>
</div>