XML 数据到多维数组

XML Data to multidimensional Array

我遇到了以下问题:将数据添加到数组后,它只存储最后插入的内容。

我使用 var_dump 从我的代码中得到以下结果:

array(5) { ["Mount01"]=> string(12) "DebugLevel#0" ["Mount02"]=> string(12) "DebugLevel#0" ["Mount03"]=> string(12) "DebugLevel#0" ["Mount04"]=> string(12) "DebugLevel#0" ["Mount05"]=> string(12) "DebugLevel#0" } 

所以它只保存了我最后一次输入的内容。但我想要这样:

array(X) { ["Mount01"]=> string(XX) "DebugLevel#0" ["Mount01"]=> string(XX) "Bla#5" ["Mount02"]=> string(XX) "DebugLevel#0" ["Mount02"]=> string(XX) "Bla#5" }

这是我的XML结构:

<Config>
  <Core>
    <Store>
      <Mount01>
                <DebugLevel>0</DebugLevel>
                <Bla>5</Bla>
      <Mount02>
                <DebugLevel>0</DebugLevel>
                <Bla>5</Bla>

这是我的代码:

class Storage{
  public static function get_storage_data()
  {
    if(file_exists('/var/www/content/data/data.xml')) :
        $xml = simplexml_load_file('/var/www/content/data/data.xml');
        foreach ($xml->Core->Store as $mounts) {
          foreach ($mounts as $mount) {
            foreach ($mount->Children() as $value) {
              $store[$mount->getName()]=$value->getName()."#".$value;
            }
          }
        }
        var_dump($store);
    else:
        write_log(sprintf("data.xml not found"));
    endif;
  }

那么,我怎样才能达到我想要的输出?也欢迎代码改进。

public static function get_storage_data(
{
    if(file_exists('/var/www/content/data/data.xml')) :
        $xml = simplexml_load_file('/var/www/content/data/data.xml');
        foreach ($xml->Core->Store as $mounts) {
          foreach ($mounts as $mount) {
            $data=[];
            foreach ($mount->Children() as $value) {
              array_push($data,[$value->getName()."#".$value]);
            }
            $store[$mount->getName()]=$data;
          }
        }
    else:
        write_log(sprintf("data.xml not found"));
    endif;
  }

回答我的问题。