array_intersect():参数 #1 不是数组?

Joa*_*ann 1 php array-intersect

对于我的代码可能有什么问题,我已经没有想法了。这个特定的类接受一个数组并将其与另一个数组进行检查以获取公共值。然后它通过 Final_post_vars_keys() 函数提供对通用值的访问。但每当我运行代码时,我都会收到错误(在标题中)。

 <?php

    class PostVarsKeys {
     private $general_keys = array("name", "email", "custom phone" , "lastname" , "firstname", "fname", "lname", "phone" , "emailaddress" ,  
            "phonenumber");
     private $post_vars_keys = array();


     public function __construct($post_keys){
      $counter=0;      
      foreach($post_keys as $key => $value):
       $this->post_vars_keys[$counter++] = $key;
      endforeach;
     }

     public function final_post_vars_keys(){
      return $final_keys = array_intersect($this->general_keys, $this->post_vars_keys);
     }
    }
Run Code Online (Sandbox Code Playgroud)

l8n*_*ite 5

将参数转换为数组:

array_intersect((array)$this->general_keys, (array)$this->post_vars_keys);
Run Code Online (Sandbox Code Playgroud)