Anil Chaudhari
Anil Chaudhari

Reputation: 841

How to get PHP object data?

I have these data formats of objects in php.

stdClass Object
(
    [@attributes] => stdClass Object
        (
            [currency] => JPY
            [rate] => 136.07
        )

)

How can I get currency and rate from this object? Thanks in advance..

Upvotes: 0

Views: 66

Answers (3)

Sunil Shrestha
Sunil Shrestha

Reputation: 218

if that so you can just call

$object->attributes()->currency;

Upvotes: 0

RightClick
RightClick

Reputation: 1112

If that object is named $obj, it's $currencyValue=$obj->{'@attributes'}->currency;

Upvotes: 2

MaggsWeb
MaggsWeb

Reputation: 3027

Try these.. ..presuming that you are using SimpleXML to parse the data.

$currency = $object->attributes()->currency;
$rate     = $object->attributes()->rate;

Upvotes: 0

Related Questions