3

Warning: Illegal offset type

i have this var from an xml output

var_dump($key);

its give me

object(SimpleXMLElement)#11 (1) { [0]=> string(5) "Cairo" } 

now i want make "Cairo" as a key to get its value like

$lang[] = array('Cairo' => "Cairo city");

the error appear when do this

echo $lang[$key];

and its give me the "Warning: Illegal offset type" because of the key is SimpleXMLElement how i can make it normal var?

5
  • 1
    How your question looks now, Try to format the question you are not a newbie to make this mistake Commented Mar 2, 2011 at 11:17
  • 1
    Is this $lang[] = array('Cairo' = "Cairo city"); on purpose? Should be $lang[] = array('Cairo' => "Cairo city"); AFAICT. (Or $lang[] = array('Cairo', "Cairo city"); depending on what you're trying to do.) Commented Mar 2, 2011 at 11:21
  • => to replace Cairo by its value "Cairo city" Commented Mar 2, 2011 at 11:24
  • 2
    Can you try with this $key=(string)$key; echo $lang[$key]; Commented Mar 2, 2011 at 11:25
  • 1
    @ Shakti Singh you r the best Commented Mar 2, 2011 at 11:36

1 Answer 1

9

Cast it to a string with (string)$key.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.