<?php
 function have_required($array , $required_fields) {
   foreach($required_fields as $field) {
     if(empty($array[$field])) return false;
    
   echo $array[$field]."<br>";}//这是有变动的地方
 } if($_POST['submitted']){//括号中的条件也改了下!
     $did=" did ";
     $didnt=" did not ";
   echo '<p>Mr ';
   echo have_required($_POST, array('name', 'email_address','age')) ? $didnt : $did;
   echo ' have all the required fields.</p>';
 }
 
?>
<form action="<?echo $PHP_SELF;?>" method=POST>
  <p>
    Name: <input type="text" name="name" ><br >
    Email address: <input type="text" name="email_address" ><br>
    Age (optional): <input type="text" name="age" >
  </p>  <p align="center">
    <input type="submit" value="submit" name="submitted">
  </p>
</form>
祝你好运罗!试试吧