Stan
Stan

Reputation: 33

Getting content from object with symbol in name

I'm getting this object with JSON and getting name by using

$programItem[0]->Name

but if I try to use

$programitem[0]->@id 

This does not work I think because of the @ but I can't remove this, anyway I can get this working?

[0] => stdClass Object
(
    [@id] => 123
    [name] => Companyname
)

Upvotes: 3

Views: 46

Answers (3)

Jasper Schiks
Jasper Schiks

Reputation: 188

You can place the key inside {''}

$programItem->{'@id'}

Upvotes: 0

Machavity
Machavity

Reputation: 31644

You can also use a variable variable to get to it

$var = '@id';
echo $a->$var;

Example

Upvotes: 0

Alex Tartan
Alex Tartan

Reputation: 6836

You can get it like

echo $obj->{'@stuff'};

See a working example:

Php code online

Upvotes: 2

Related Questions