2

Possible Duplicate:
PHP get values from SimpleXMLElement array

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [TotalAmount] => 4.75
        )
)

$services_arr->attributes returns null

$services_arr->@attributes returns an error

My question is: How to get toal amount 4.75 ?

Community
  • 1
  • 1
test
  • 17
  • 1
  • 5

2 Answers2

1

To return total amount in float:

$total_amount = (float)$services_arr['TotalAmount'];
uzyn
  • 6,625
  • 5
  • 22
  • 41
0

The best would be to create a function inside your class, that returns the desired value something like this:

public function getTotalAmount () {
  return $this -> total_amount;
}

And ask for it like this:

$services_arr -> getTotalAmount();

This will make the code safer too, it's not good practise, to ask directly for values.

Peon
  • 7,902
  • 7
  • 59
  • 100