stdClass Object and array how to using php

后端 未结 3 1095
孤街浪徒
孤街浪徒 2020-12-18 07:28

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

stdClass Object
(
    [checkins] => stdClass Object
        (
            [count] => 12
          


        
相关标签:
3条回答
  • 2020-12-18 08:00

    change

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

    changed to

    $a1[] = $checkins->items[$i]->venue->id; 
    
    0 讨论(0)
  • 2020-12-18 08:04

    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

    0 讨论(0)
  • 2020-12-18 08:16

    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;
    
    0 讨论(0)
提交回复
热议问题