Check if value is null in array in object?

301 views Asked by At

Here is the $object that Microsoft is returning to me:

object(Microsoft\Graph\Model\Event)#56 (1) {
  ["_propDict":protected]=>
  array(2) {
    ["@odata.context"]=>
    string(245) "https://graph.microsoft.com/v1.0/$metadata#users('email%40outlook.com')/calendars('AAAAAAAAAAAAAAAAAAAAAAAA')/calendarView"
    ["value"]=>
    array(0) {
    }
  }
}

I'm trying to check if value's array contains nothing in it. I'm having trouble accessing "value" as it just says array. Here is what I've already tried doing:

$object->array;

$object->array();

$object[0];

foreach ($object as $key) {
    var_dump($key);
}

None of those work.


I'm trying to do something like this:

if(empty($object->array['value'])) {
    echo 'value is empty';
}
1

There are 1 answers

0
Vadim Gremyachev On

Entity.getProperties() function could be utilized for that purpose which returns the list of properties. Entity is a base class for Event entity.

The following example demonstrates how to determine whether entity contains property using array_key_exists function:

$requestUrl = "https://graph.microsoft.com/v1.0/drives/$targetDriveId";
$drive = $this->client->createRequest("GET", $requestUrl)
     ->setReturnType(Model\Drive::class)
     ->execute();

$properties = $drive->getProperties();  //get all properties
if (array_key_exists('id', $properties)) { //verify for id property
    print $properties["id"];
}