1

所以,我正在尝试解析和 xml 并从中获取一些值:

    $xml = simplexml_load_string(file_get_contents('http://www.bnr.ro/nbrfxrates.xml'));
    $currency = [];

    foreach($xml->Body->Cube->Rate as $rate)
    {
        $currency[] = [
            "name" => $rate["currency"],
            "value" => $rate,
            "multiplier" => $rate["multiplier"]
        ];
    }

    return $currency;

我的 $rate 变量应该是 Rate 标签内的值(例如:1.0806),而不是它给我这个:

object(SimpleXMLElement)[110]
   public '@attributes' => 
      array (size=1)
         'currency' => string 'AED' (length=3)
4

1 回答 1

1

将 $rate 转换为 (string) 将起作用:

    $currency[] = [
        "name" => $rate["currency"],
        "value" => (string)$rate,
        "multiplier" => $rate["multiplier"]
    ];
于 2016-08-18T11:09:55.373 回答