Automattic\WooCommerce\Vendor\GraphQL\Utils

Utils::extractKey │ public static │ WC 1.0

Try to extract the value for a key from an object like value.

Method of the class: Utils{}

No Hooks.

Returns

mixed.

Usage

$result = Utils::extractKey( $objectLikeValue, $key );
$objectLikeValue(mixed) (required)
.
$key(string) (required)
.

Utils::extractKey() code WC 11.1.2

public static function extractKey($objectLikeValue, string $key)
{
    if (is_array($objectLikeValue) || $objectLikeValue instanceof \ArrayAccess) {
        return $objectLikeValue[$key] ?? null;
    }

    if (is_object($objectLikeValue)) {
        return $objectLikeValue->{$key} ?? null;
    }

    return null;
}