You are here

public function CsvEncoder::formatRow in CSV Serialization 8

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

Formats all cells in a given CSV row.

This flattens complex data structures into a string, and formats the string.

Parameters

array $row: A row of data. This may be a flat or multidimensional array.

Return value

array A flat array of key/value, with value flattened into string.

File

src/Encoder/CsvEncoder.php, line 215

Class

CsvEncoder
Adds CSV encoder support for the Serialization API.

Namespace

Drupal\csv_serialization\Encoder

Code

public function formatRow(array $row) {
  $formatted_row = [];
  foreach ($row as $column_name => $cell_data) {
    if (is_array($cell_data)) {
      $cell_value = $this
        ->flattenCell($cell_data);
    }
    else {
      $cell_value = $cell_data;
    }
    $formatted_row[] = $this
      ->formatValue($cell_value);
  }
  return $formatted_row;
}