1

New to PHP....I am trying to access a value in an array that comes from a decoded json file. 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?

Thanks!

nickb
  • 59,313
  • 13
  • 108
  • 143
pigishpig
  • 113
  • 3

1 Answers1

0

Class methods and properties are accessed with the -> operator:

echo $arr[1]->fcttext;

Check out Reference - What does this symbol mean in PHP? when you are unsure on the meaning of an operator in php.

Community
  • 1
  • 1
Bailey Parker
  • 15,599
  • 5
  • 53
  • 91
  • That was easy. Thanks so much! – pigishpig Jul 30 '12 at 01:53
  • @pigishpig No problem. Welcome to SO. An important part of the community is voting to indicate the quality of good or bad answers and marking as solved. When you mark as solved it not only indicates this to the community but also positively reflects on your accept percentage. For more info see http://stackoverflow.com/faq#howtoask and ask if you have any questions! – Bailey Parker Jul 30 '12 at 03:19