Php 不显示数组中的值

Php 不显示数组中的值,php,arrays,forms,oop,foreach,Php,Arrays,Forms,Oop,Foreach,我有一个表单,其中包含此代码,因此我可以在检查类中的字段时回显错误: <?php if( isset($_POST['send'])){ $new_user = new Register(); $new_user->check_required_fields($_POST); $new_user->display_errors(); } ?> 课程是: <?php class Regis

我有一个表单,其中包含此代码,因此我可以在检查类中的字段时回显错误:

<?php if( isset($_POST['send'])){     
        $new_user = new Register();
        $new_user->check_required_fields($_POST);
        $new_user->display_errors();
    } 

?>
课程是:

<?php
    class Register extends Database
    {
        public $fname;
        public $lname;
        public $uname;
        public $email;
        public $pass1;
        public $pass2;
        public $year;
        public $month;
        public $day;
        public $required_array;
        public $error;
        public $errors = array();

        public function check_required_fields($required_array)
        {
             if(in_array('', $required_array)) {
                 $errors[] = "One or more fields are missing";
                 //var_dump($errors);
             }
             else
             { 
                 $errors[] = "All fields are ok";
                 $this->fname = $required_array['fname'];
                 $this->lname = $required_array['lname'];
                 $this->uname = $required_array['lname'];
                 $this->email = $required_array['email'];
                 $this->pass1 = $required_array['pass1'];
                 $this->pass2 = $required_array['pass2'];
                 $this->year = $required_array['year'];
                 $this->month = $required_array['month'];
                 $this->day = $required_array['day'];
             }

         }


         public function display_errors ($errors)
         {
             foreach ($errors as $error){
                 echo $error;
             }

         }
出于某种原因,它不会显示$errors数组,我不知道为什么?如果有任何帮助,我将不胜感激。

尝试使用

$this->errors
在check_required_字段和display_errors字段中

 public function display_errors ($errors)
 {
     foreach($errors as $error){
            echo $error;
        }

 }
在foreach语句中使用的$errors是函数display\u errors的参数列表中的$errors,当调用函数时,没有给出任何参数,因此该变量将为空


您应该在foreach语句中使用$this->errors,并在display\u errors参数:public function display中去掉$errors_errors@Josh乍一看,我以为这些是C指针。令人毛骨悚然。@Stanislav我想它会指向指针,但右侧会做什么?错误修复,抱歉,这是我的第一个帖子:@Josh它会做可怕的事情;-没什么,只是一个编译错误。