【发布时间】:2012-07-23 09:41:57
【问题描述】:
SimpleXMLElement Object
(
[@attributes] => Array
(
[TotalAmount] => 4.75
)
)
$services_arr->attributes 返回空值
$services_arr->@attributes 返回错误
我的问题是:如何获得总金额4.75?
【问题讨论】:
SimpleXMLElement Object
(
[@attributes] => Array
(
[TotalAmount] => 4.75
)
)
$services_arr->attributes 返回空值
$services_arr->@attributes 返回错误
我的问题是:如何获得总金额4.75?
【问题讨论】:
以浮点数返回总金额:
$total_amount = (float)$services_arr['TotalAmount'];
【讨论】:
最好的办法是在你的类中创建一个函数,它返回所需的值,如下所示:
public function getTotalAmount () {
return $this -> total_amount;
}
然后像这样要求它:
$services_arr -> getTotalAmount();
这也会使代码更安全,直接询问值不是好习惯。
【讨论】: