when I use simplexml_load_string , It return multi dimensional object. I made some test code like this, and it error, can anyone help me to correct the code, teach me how to declare and make this code alive, Thank you. $aaa = new stdClass(); $aaa->cat[0] = "cat0"; $aaa->cat[1] = "cat1"; $aaa->cat[0]->name = "Hello 0"; $aaa->cat[1]->name = "Hello 1"; $aaa->cat[0]->Lastname = "Last 0"; $aaa->cat[1]->Lastname = "Last 1";
$string = <<<XML <?xml version='1.0'?> <document> <title>Forty What?</title> <from>Joe</from> <to>Jane</to> <family> <father>PHP</father> <mother>MYSQL</mother> <child>HTML</child> <brother>ASP</brother> </family> <body> I know that's the answer -- but what's the question? </body> </document> XML; $aaa = simplexml_load_string($string); //<---important line, always use simplexml_load_string. echo $aaa->body; echo $aaa->family->father; echo $aaa->family->brother; //You can change the property $aaa->body = 'Meowww'; echo $aaa->body;