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 error: Undefined index (key)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
Arraybefore the argument in the argument signature.You can also check for an array key being set with
isset()orarray_key_exists(), the latter which works with keys with theNULLvalue.