How to get the value of an element of an object that has a channel?

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

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

I have never seen a pipe in a member name before.

+6
source share
2 answers

You can use curly braces and put the field name in a string:

 $obj->{'profile|title'} 
+6
source

you can use

 $obj->{'profile|title'} 

Since you just use it as a dumb data store, you can also use it as an array

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

This would be more useful if you use a lot of values ​​from this method or you need to iterate over it.

+5
source

Source: https://habr.com/ru/post/899744/


All Articles