is there a way to pass an array to a member function? i tried this code:
class Testing
{
   public function set($arr)
   { 
      echo $arr['key'];
   }
}
but i got this开发者_StackOverflow社区 error: Undefined index (key)
You can pass an array, just like how you have done.
The problem is, the array you passed does not have a member with the a key of key.
You can enforce passing an array by placing a preceding Array before the argument in the argument signature.
public function set(Array $arr) { ... } 
You can also check for an array key being set with isset() or array_key_exists(), the latter which works with keys with the NULL value.
You pass an array to a method, like you pass any other type to a method
$o = new Testing;
$array = array('key' => 'Hello World');
$o->set($array);
In your case it seems, that your array is just invalid (=> it doesn't have a key named "key").
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论