如何正确读取xml中的数组与json转换在php数组中

how correct read array was from xml with json convert in php array?

     <php?
    $xmlfile = file_get_contents('data.xml');
    $ob= simplexml_load_string($xmlfile);
    $json  = json_encode($ob);
    $configData = json_decode($json, true);
    foreach($configData["id"] as $configData)
    {
    echo $configData["name"];
    echo $configData["image"];
     echo $configData["id"];

    }

?>

Warning: Invalid argument supplied for foreach in /data.php on line 10

Try using simplexml_load_file function. I have always found success in using this whenever you are dealing with xml files.

If you want a list of the ids, you should stick to using SimpleXML...

$xmlfile = simplexml_load_file("data.xml");

foreach ( $xmlfile->smarza as $data )   {
    echo $data->id.PHP_EOL;
}

This loads the file using simplexml_load_file() and then loops in the foreach() it goes over each <smarza> element (using $xmlfile->smarza). The access the <id> element using $data->id.