Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 675 Bytes

README.md

File metadata and controls

42 lines (28 loc) · 675 Bytes

str_putcsv

Packagist

The missing str_putcsv function for PHP

Inverse of the PHP native function str_getcsv.

Installation

composer require mll-lab/str_putcsv

Usage

<?php declare(strict_types=1);

require 'vendor/autoload.php';

$entries = [
    [1, 'a'],
    [2, 'b'],
];

$csv = '';
foreach ($entries as $entry) {
    $csv .= str_putcsv($entry) . PHP_EOL;
}
var_dump($csv);

Result:

string(8) "1,a
2,b
"

Credits

Based on https://github.com/kafene/str_putcsv