Skip to content

Commit

Permalink
Patch first key reference on data serialize method
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Oct 12, 2020
1 parent 62a396a commit de2526d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,13 @@ public static function serializeData($data, array $options = [])
$omit = [];
}

$options = self::processOptions($options);
$csv = '';
$options = self::processOptions($options);
$csv = '';
$firstKey = array_keys($data)[0];

if (is_array($data) && isset($data[0]) &&
(is_array($data[0]) || ($data[0] instanceof \ArrayObject)) && ($options['fields'])) {
$csv .= self::getFieldHeaders((array)$data[0], $options['delimiter'], $omit);
if (is_array($data) && isset($data[$firstKey]) &&
(is_array($data[$firstKey]) || ($data[$firstKey] instanceof \ArrayObject)) && ($options['fields'])) {
$csv .= self::getFieldHeaders((array)$data[$firstKey], $options['delimiter'], $omit);
}

// Initialize and clean the field values.
Expand Down

0 comments on commit de2526d

Please sign in to comment.