user903277
user903277

Reputation: 109

How do I get the value of an object member that has a pipe?

Given this object, how do I output the value of pipe|title?

stdClass Object
(
    [profile|title] => John Doe
)

I've never seen a pipe in a member name before.

Upvotes: 6

Views: 57

Answers (2)

Jeff Day
Jeff Day

Reputation: 3717

You can use

$obj->{'profile|title'}

Since you're just using it as a stupid data store, you can also cast it as an array

$arr = (array) $obj;
$arr['profile|title'];

This would be more useful if you're using a lot of values out of it this way or you need to iterate over it.

Upvotes: 5

user142162
user142162

Reputation:

You can make use of the curly brackets and put the field name in a string:

$obj->{'profile|title'}

Upvotes: 6

Related Questions