SimpleXMLElement Object
(
[@attributes] => Array
(
[TotalAmount] => 4.75
)
)
$services_arr->attributes
null を返します
$services_arr->@attributes
エラーを返します
私の質問は次のとおりです。合計金額を取得するにはどうすればよい4.75
ですか?
SimpleXMLElement Object
(
[@attributes] => Array
(
[TotalAmount] => 4.75
)
)
$services_arr->attributes
null を返します
$services_arr->@attributes
エラーを返します
私の質問は次のとおりです。合計金額を取得するにはどうすればよい4.75
ですか?
合計金額を float で返すには:
$total_amount = (float)$services_arr['TotalAmount'];
クラス内に次のような目的の値を返す関数を作成するのが最善です。
public function getTotalAmount () {
return $this -> total_amount;
}
そして、このようにそれを求めてください:
$services_arr -> getTotalAmount();
これにより、コードもより安全になります。値を直接要求することはお勧めできません。