Accessing information from an object

1

How would I go about accessing Type and cm with this array?

object(stdClass)#38 (3) {
  ["op"]=>
  string(1) "&"
  ["c"]=>
  array(1) {
    [0]=>
    object(stdClass)#32 (3) {
      ["type"]=>
      string(10) "completion"
      ["cm"]=>
      int(1227)
      ["e"]=>
      int(1)
    }
  }
  ["showc"]=>
  array(1) {
    [0]=>
    bool(true)
  }
}
    
asked by anonymous 07.10.2016 / 16:23

1 answer

3

If the data is repeated, you can use a loop to access it.

foreach ($object->c as $key => $value) {
        echo $value->type;
        echo $value->cm;
}

If you access it directly, it would look like this:

echo $object->c[0]->type; // minúsculo, e não maiúsculo
echo $object->c[0]->cm;

Note : You asked about "accessing a array ", but this is an object ( stdClass , which is the default PHP object).

Related:

What is the purpose of stdClass in PHP?

    
07.10.2016 / 16:26