-1

Possible Duplicate:
How do I access a PHP object attribute having a dollar sign?

How do I access the value of an object where the key contains a '$'. I have an array named "entries" as follows:

Array
(
    [0] => stdClass Object
        (
            [id] => stdClass Object
                (
                    [$t] => xyz
                )
        )
)

I want to access the value of [$t], ie. xyz. The following command returns null:

echo $entries[0]->id->$t;

What syntax should I use?

Community
  • 1
  • 1
victor_golf
  • 195
  • 2
  • 2
  • 10

1 Answers1

3

Use the {expression} syntax:

$entries[0]->id->{'$t'}

In case you are curious: echo $entries[0]->id->$t; would work if you did $t = '$t'; first.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636