You are here

function shorten_get_value_from_array in Shorten URLs 7.2

Extracts a value from an associative array given an element name or path.

Parameters

string $contents: The associative array containing the data to extract.

string $expression: A single element name or a dot notation path expression.

Return value

string A value from the associative array.

1 call to shorten_get_value_from_array()
shorten_fetch in ./shorten.module
Downloads the response of the URL abbreviation service.

File

./shorten.module, line 421
Shortens URLs via external services.

Code

function shorten_get_value_from_array($contents, $expression) {
  $exploded_expression = str_getcsv($expression, '.', '"', '\\');
  if (count($exploded_expression) === 1) {
    if (!isset($contents[$expression])) {
      watchdog('shorten', 'json response does not contain specified member name or path expression: @expression', array(
        '@expression' => $expression,
      ));
      return NULL;
    }
    return $contents[$expression];
  }
  return shorten_get_path_in_array($contents, $exploded_expression);
}