Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CsvEncoder.php

function CsvEncoder::flatten

Flattens an array and generates keys including the path.

1 call to CsvEncoder::flatten()
CsvEncoder::encode in vendor/symfony/serializer/Encoder/CsvEncoder.php
Encodes data into the given format.

File

vendor/symfony/serializer/Encoder/CsvEncoder.php, line 223

Class

CsvEncoder
Encodes CSV data.

Namespace

Symfony\Component\Serializer\Encoder

Code

private function flatten(iterable $array, array &$result, string $keySeparator, string $parentKey = '', bool $escapeFormulas = false) : void {
    foreach ($array as $key => $value) {
        if (is_iterable($value)) {
            $this->flatten($value, $result, $keySeparator, $parentKey . $key . $keySeparator, $escapeFormulas);
        }
        else {
            if ($escapeFormulas && \in_array(substr((string) $value, 0, 1), self::FORMULAS_START_CHARACTERS, true)) {
                $result[$parentKey . $key] = "'" . $value;
            }
            else {
                // Ensures an actual value is used when dealing with true and false
                $result[$parentKey . $key] = false === $value ? 0 : (true === $value ? 1 : $value);
            }
        }
    }
}
RSS feed
Powered by Drupal