douzhao6584
douzhao6584
2012-10-25 13:00

使用PHP从数组中获取特定值

已采纳

If I have an array in the following format:

Array ( [0] => stdClass Object ( [id] => 1 [c] => 1 [q] => value 1. ) [1] => stdClass Object ( [id] => 2 [c] => 1 [q] => value 2...

and I need to get

value 1

Shouldn't I be able to get it by doing something like?

$myArray[0]['q']

FOr some reason I'm not getting anything...

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • dongxun7301 dongxun7301 9年前

    The element is inside an object, you need to do,

      echo $myArray[0]->q;
    
    点赞 评论 复制链接分享
  • doujingao6210 doujingao6210 9年前

    You need to use $myArray[0]->q it is an object not an array.

    点赞 评论 复制链接分享

相关推荐