stdClass的对象和阵列如何使用PHP [英] stdClass Object and array how to using php

查看:122
本文介绍了stdClass的对象和阵列如何使用PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让十二IDS,这种结构说明:

I'm trying to get the twelve ids that this structure shows:

stdClass Object
(
    [checkins] => stdClass Object
        (
            [count] => 12
            [items] => Array
                (
                    [0] => stdClass Object
                        (

                            [venue] => stdClass Object
                                (
                                    [id] => 4564654646456
                                    .
                                    .

我做的:

$checkins = $fsObjUnAuth->get("/users/self/checkins");
$count = $checkins ->response->checkins->count;  // so I can  get 12

 for( $i = 0; $i < $count; $i ++)
  {
      $a1[] = $checkins['items'][$i]['venue']['id'];  //two tries
      $a2[] = $checkins ->response->checkins->items->$i->venue->id;
        echo $i; echo ": ";
        echo $a1;echo"<br>";
        echo $a2;echo"<br>"
  } 

但我得到:
致命错误:无法使用类型stdClass的对象为线阵列。

But I get: Fatal error: Cannot use object of type stdClass as array in line..

请有人可以告诉我怎么做呢?

Please can someone show me how to do this?

非常感谢

推荐答案

您无法通过数组下标运算符访问对象成员 []

You cannot access object members via the array subscript operator [].

您必须使用 - &GT; 运营商:

$x = new StdClass();

$x->member = 123;

在你的情况,你将不得不使用一种混合物,因为你有一个对象( $签入)与成员( $项目),这是一个数组,其中包含其他对象。

In your case you'll have to use a mixture, since you have an object ($checkins) with a member ($items) which is an array, which contains additional objects.

$a1[] = $checkins->items[$i]->venue->id;

这篇关于stdClass的对象和阵列如何使用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆