Sunday, September 23, 2018

json - Get a PHP object property that is a number




I'm trying to get a property from JSON data decoded into a PHP object. It's just a YouTube data API request that returns a video object that has a content object liks so;



[content] => stdClass Object
(
[5] => https://www.youtube.com/v/r4ihwfQipfo?version=3&f=videos&app=youtube_gdata
[1] => rtsp://v4.cache7.c.youtube.com/CiILENy73wIaGQn6pSL0waGIrxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
[6] => rtsp://v6.cache3.c.youtube.com/CiILENy73wIaGQn6pSL0waGIrxMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
)



Doing



$object->content->5


Throws "unexpected T_DNUMBER" - which makes perfect sense. But how do I get the value of a property that is a number?



I'm sure I should know this. Thanks in advance.


Answer



This should work:




$object->content->{'5'}


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...