I’m getting
illegal offset type
error for every iteration of this code. Here’s the code :
$s = array();
for($i = 0; $i < 20; $i++){
$source = $xml->entry[$i]->source;
$s[$source] += 1;
}
print_r($s)
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.
Illegal offset type errors occur when you attempt to access an array index using an object or an array as the index key.
Example:
Your
$xmlarray contains an object or array at$xml->entry[$i]->sourcefor some value of$i, and when you try to use that as an index key for$s, you get that warning. You’ll have to make sure$xmlcontains what you want it to and that you’re accessing it correctly.