You are here

protected function CsvEncoder::flattenCell in CSV Serialization 8

Same name and namespace in other branches
  1. 8.2 src/Encoder/CsvEncoder.php \Drupal\csv_serialization\Encoder\CsvEncoder::flattenCell()

Flattens a multi-dimensional array into a single level.

Parameters

array $data: An array of data for be flattened into a cell string value.

Return value

string The string value of the CSV cell, un-sanitized.

1 call to CsvEncoder::flattenCell()
CsvEncoder::formatRow in src/Encoder/CsvEncoder.php
Formats all cells in a given CSV row.

File

src/Encoder/CsvEncoder.php, line 241

Class

CsvEncoder
Adds CSV encoder support for the Serialization API.

Namespace

Drupal\csv_serialization\Encoder

Code

protected function flattenCell(array $data) {
  $depth = $this
    ->arrayDepth($data);
  if ($depth == 1) {

    // @todo Allow customization of this in-cell separator.
    return implode('|', $data);
  }
  else {
    $cell_value = "";
    foreach ($data as $item) {
      $cell_value .= '|' . $this
        ->flattenCell($item);
    }
    return trim($cell_value, '|');
  }
}