开发者

array_intersect(): Argument #1 is not an array?

I am running out of ideas as to what could be wrong with my code. This particular class accepts an array and checks it against another array to get the common values. Then it provides access to the common values thru final_post_vars_keys() function. But I get the error(in the title) whenever I run the code.

 <?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_开发者_如何学Gokeys = array_intersect($this->general_keys, $this->post_vars_keys);
     }
    }


Cast the arguments as arrays:

array_intersect((array)$this->general_keys, (array)$this->post_vars_keys);


$counter variable is initialized to zero every time in the foreach loop. Have you tried taking it out?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜