Helper/File.php
private function arrayToCsv(
        array &$fields,
        $delimiter,
        $enclosure,
        $encloseAll = false,
        $nullToMysqlNull = false
    ) {
        $delimiterEsc = preg_quote($delimiter, '/');
        $enclosureEsc = preg_quote($enclosure, '/');

        $output = [];
        foreach ($fields as $field) {
            if ($field === null && $nullToMysqlNull) {
                $output[] = 'NULL';
                continue;
            }

            // Enclose fields containing $delimiter, $enclosure or whitespace
            if ($encloseAll
                || preg_match(
                    "/(?:$delimiterEsc|$enclosureEsc|\s)/",
                    $field
                )
            ) {
                $output[] = $enclosure . str_replace(
                    $enclosure,
                    $enclosure . $enclosure,
                    $field
                ) . $enclosure;
            } else {
                $output[] = $field;
            }
        }

        return implode($delimiter, $output) . "\n";
    }
private function arrayToCsv(
        array &$fields,
        $delimiter,
        $enclosure,
        $encloseAll = false,
        $nullToMysqlNull = false
    ) {
        $delimiterEsc = preg_quote($delimiter, '/');
        $enclosureEsc = preg_quote($enclosure, '/');

        $output = [];
        foreach ($fields as $field) {
            if ($field === null && $nullToMysqlNull) {
                $output[] = 'NULL';
                continue;
            }

            // Enclose fields containing $delimiter, $enclosure or whitespace
            if ($encloseAll
                || preg_match(
                    "/(?:$delimiterEsc|$enclosureEsc|\s)/",
                    $field
                )
            ) {
                $output[] = $enclosure . str_replace(
                    $enclosure,
                    $enclosure . $enclosure,
                    $field
                ) . $enclosure;
            } else {
                $output[] = $field;
            }
        }

        return implode($delimiter, $output) . "\n";
    }
private function arrayToCsv ( array & $ fields , $ delimiter , $ enclosure , $ encloseAll = false , $ nullToMysqlNull = false ) { $ delimiterEsc = preg_quote ( $ delimiter , '/' ) ; $ enclosureEsc = preg_quote ( $ enclosure , '/' ) ; $ output = [ ] ; foreach ( $ fields as $ field ) { if ( $ field === null && $ nullToMysqlNull ) { $ output [ ] = 'NULL' ; continue ; } // Enclose fields containing $delimiter, $enclosure or whitespace if ( $ encloseAll || preg_match ( "/(?:$delimiterEsc|$enclosureEsc|\s)/" , $ field ) ) { $ output [ ] = $ enclosure . str_replace ( $ enclosure , $ enclosure . $ enclosure , $ field ) . $ enclosure ; } else { $ output [ ] = $ field ; } } return implode ( $ delimiter , $ output ) . "\n" ; }
Convert array into the csv.

@param array $fields
@param string $delimiter
@param string $enclosure
@param bool $encloseAll
@param bool $nullToMysqlNull

@return string
Convert array into the csv .