private static function Inline::dumpArray in Plug 7
Dumps a PHP array to a YAML string.
Parameters
array $value The PHP array to dump:
bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise:
bool $objectSupport true if object support is enabled, false otherwise:
Return value
string The YAML string representing the PHP array
1 call to Inline::dumpArray()
- Inline::dump in lib/
Symfony/ yaml/ Symfony/ Component/ Yaml/ Inline.php - Dumps a given PHP variable to a YAML string.
File
- lib/
Symfony/ yaml/ Symfony/ Component/ Yaml/ Inline.php, line 169
Class
- Inline
- Inline implements a YAML parser/dumper for the YAML inline syntax.
Namespace
Symfony\Component\YamlCode
private static function dumpArray($value, $exceptionOnInvalidType, $objectSupport) {
// array
$keys = array_keys($value);
$keysCount = count($keys);
if (1 === $keysCount && '0' == $keys[0] || $keysCount > 1 && array_reduce($keys, function ($v, $w) {
return (int) $v + $w;
}, 0) === $keysCount * ($keysCount - 1) / 2) {
$output = array();
foreach ($value as $val) {
$output[] = self::dump($val, $exceptionOnInvalidType, $objectSupport);
}
return sprintf('[%s]', implode(', ', $output));
}
// mapping
$output = array();
foreach ($value as $key => $val) {
$output[] = sprintf('%s: %s', self::dump($key, $exceptionOnInvalidType, $objectSupport), self::dump($val, $exceptionOnInvalidType, $objectSupport));
}
return sprintf('{ %s }', implode(', ', $output));
}