访问stdClass对象数组

时间:2012-07-30 01:49:45

标签: php

PHP新手....我试图访问来自解码的json文件的数组中的值。我将我的变量打印到屏幕上,然后返回...

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
    ...
    ) 
) 

如何访问例如第1期的fcttext?

谢谢!

1 个答案:

答案 0 :(得分:0)

使用->运算符访问类方法和properties

echo $arr[1]->fcttext;

当您不确定php中运算符的含义时,请查看Reference - What does this symbol mean in PHP?

相关问题