1

对于我的代码可能有什么问题,我已经没有想法了。这个特定的类接受一个数组,并根据另一个数组检查它以获得公共值。然后它通过 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);
     }
    }
4

2 回答 2

4

将参数转换为数组:

array_intersect((array)$this->general_keys, (array)$this->post_vars_keys);
于 2010-11-14T07:21:42.090 回答
1

$counterforeach变量在循环中每次都初始化为零。你试过把它拿出来吗?

于 2010-11-14T06:57:10.660 回答