function public static function Unicode::castToString

8.x-3.x Unicode.php public static Unicode::castToString($value = NULL, $delimiter = '.')

Casts a value to a string, recursively if an array.

Parameters

mixed $value: Any value.

string $delimiter: The delimiter to use when joining multiple items in an array.

Return value

string The cast string.

Class

Unicode
Extends \Drupal\Component\Utility\Unicode.

Namespace

Drupal\bootstrap\Utility

Source src/Utility/Unicode.php (line 27)

public static function castToString($value = NULL, $delimiter = '.') {
  if (is_object($value) && method_exists($value, '__toString')) {
    return (string) ($value->__toString() ? : '');
  }
  if (is_array($value)) {
    foreach ($value as $key => $item) {
      $value[$key] = static::castToString($item, $delimiter);
    }
    return implode($delimiter, array_filter($value));
  }
  // Handle scalar values.
  if (isset($value) && is_scalar($value) && !is_bool($value)) {
    return (string) $value;
  }
  return '';
}