src/Utilities/Arrays.php
public static function values2csv(array $array, $separator = ',')
    {
        /*
         * No elements?
         * Nothing to do
         */
        if (empty($array)) {
            return null;
        }

        $rows = [];
        $lineSeparator = "\n";

        foreach ($array as $row) {
            /*
             * I have to use html_entity_decode() function here, because some string values can contain
             * entities with semicolon and this can destroy the CSV column order.
             */

            if (is_array($row) && !empty($row)) {
                foreach ($row as $key => $value) {
                    $row[$key] = html_entity_decode($value);
                }

                $rows[] = implode($separator, $row);
            }
        }

        if (empty($rows)) {
            return '';
        }

        return implode($lineSeparator, $rows);
    }
public static function values2csv(array $array, $separator = ',')
    {
        /*
         * No elements?
         * Nothing to do
         */
        if (empty($array)) {
            return null;
        }

        $rows = [];
        $lineSeparator = "\n";

        foreach ($array as $row) {
            /*
             * I have to use html_entity_decode() function here, because some string values can contain
             * entities with semicolon and this can destroy the CSV column order.
             */

            if (is_array($row) && !empty($row)) {
                foreach ($row as $key => $value) {
                    $row[$key] = html_entity_decode($value);
                }

                $rows[] = implode($separator, $row);
            }
        }

        if (empty($rows)) {
            return '';
        }

        return implode($lineSeparator, $rows);
    }
public static function values2csv ( array $ array , $ separator = ',' ) { /*
         * No elements?
         * Nothing to do
         */ if ( empty ( $ array ) ) { return null ; } $ rows = [ ] ; $ lineSeparator = "\n" ; foreach ( $ array as $ row ) { /*
             * I have to use html_entity_decode() function here, because some string values can contain
             * entities with semicolon and this can destroy the CSV column order.
             */ if ( is_array ( $ row ) && ! empty ( $ row ) ) { foreach ( $ row as $ key => $ value ) { $ row [ $ key ] = html_entity_decode ( $ value ) ; } $ rows [ ] = implode ( $ separator , $ row ) ; } } if ( empty ( $ rows ) ) { return '' ; } return implode ( $ lineSeparator , $ rows ) ; }
Converts given array's rows to csv string

@param array  $array     Data to be converted. It have to be an array that represents database table.
@param string $separator (optional) Separator used between values. Default: ",".
@return null|string
Converts given array s rows to csv string