简体   繁体   English

访问stdClass对象的数组

[英]Accessing Array of stdClass Objects

New to PHP....I am trying to access a value in an array that comes from a decoded json file. PHP的新手...。我正在尝试访问来自解码的json文件的数组中的值。 I printed my variable to the screen, and this was returned... 我将变量打印到屏幕上,并返回了...

Array ( 
[0] => stdClass Object ( 
    [period] => 0 
    [title] => Sunday 
    [fcttext] => Mostly cloudy with a chance of ...
    [pop] => 50 ) 
[1] => stdClass Object ( 
    [period] => 1 
    [title] => Sunday Night 
    [fcttext] => Partly cloudy. Low of 64F. Win.... 
    [pop] => 10 ) 
[2] => stdClass Object ( 
    [period] => 2 
    [title] => Monday 
    [fcttext] => Partly cloudy. High of 90F. Winds less than 5 mph. 
    [pop] => 10 ) 
[3] => stdClass Object ( 
    [period] => 3
    ...
    ) 
) 

How do I access, for instance, the fcttext from period 1? 例如,如何访问时期1的fcttext?

Thanks! 谢谢!

Class methods and properties are accessed with the -> operator: 使用->运算符访问类方法和属性

echo $arr[1]->fcttext;

Check out Reference - What does this symbol mean in PHP? 退房参考-这个符号在PHP中是什么意思? when you are unsure on the meaning of an operator in php. 当您不确定php中运算符的含义时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM