Accessing information from an Object

Asked

Viewed 57 times

1

How would I access Type and cm with that 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)
  }
}

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 were to access directly, it would be so:

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

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

Related:

What is the purpose of stdClass in PHP?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.