Flow\JSONPath\AccessHelper::keyExists PHP Method

keyExists() public static method

public static keyExists ( $collection, $key, $magicIsAllowed = false )
    public static function keyExists($collection, $key, $magicIsAllowed = false)
    {
        if ($magicIsAllowed && is_object($collection) && method_exists($collection, '__get')) {
            return true;
        }
        if (is_array($collection) || $collection instanceof \ArrayAccess) {
            return array_key_exists($key, $collection);
        } else {
            if (is_object($collection)) {
                return property_exists($collection, $key);
            }
        }
    }

Usage Example

 /**
  * @param $collection
  * @return array
  */
 public function filter($collection)
 {
     $return = [];
     foreach ($this->token->value as $index) {
         if (AccessHelper::keyExists($collection, $index, $this->magicIsAllowed)) {
             $return[] = AccessHelper::getValue($collection, $index, $this->magicIsAllowed);
         }
     }
     return $return;
 }
All Usage Examples Of Flow\JSONPath\AccessHelper::keyExists