stdClass Object and array how to using php

邮差的信 提交于 2019-11-29 07:37:34

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

You have to use the -> operator:

$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;

Here is a simple solution to convert a stdClass Object in array in php with function get_object_vars

Look at : http://php.net/manual/fr/function.get-object-vars.php

Ex :

debug($array);
$var = get_object_vars($array);
debug($var);

Or replace debug by print_r

I'm use CakePHP framework

Cdt

change

$a1[] = $checkins['items'][$i]['venue']['id'];

changed to

$a1[] = $checkins->items[$i]->venue->id; 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!