I'm creating an array using an xml file. I've done this before so I don't know why it's a problem, but when I use one of the variables as an array to assign another variable to the array, I get "Warning: Illegal offset type".
Here's what I'm doing:
$stateData = array();
$stateData["99"]="All States";
$stateXmlFile = simplexml_load_file("../../resources/StateCodes.xml");
foreach($stateXmlFile->state as $stateskey){
$offset = $stateskey->number;
$stateData[$offset] = $stateskey->alpha;
}
The $stateskey->number from xml will be a two digit number. I've done things like this before and never had any issues. If somebody could please tell me what I'm doing wrong and how to work around this, I'd be greatly appreciative.
Thanks.
$stateskey->numberis an integer (and not a SimpleXML object or the like)? Do avar_dumpof it, please.intvalandtrim: eval.in/59898 - and another duplicate here: PHP XML: Illegal Offset, but it is in array? (Sep 2011)