Skip to content

Instantly share code, notes, and snippets.

@goedecke
Created November 23, 2016 18:10
Show Gist options
  • Save goedecke/2d7ee06aacaaa4f1321427b0c46464aa to your computer and use it in GitHub Desktop.
Save goedecke/2d7ee06aacaaa4f1321427b0c46464aa to your computer and use it in GitHub Desktop.
Convertir Array a CSV
//Function
function csv($array) {
$csv = "";
for( $i = 0; $i < count($array); $i++ ) {
$csv .= '"' . str_replace('"', '""', $array[$i]) . '"';
if( $i < count($array) - 1 ) $csv .= ",";
}
return $csv;
}
//Output
$a = array("item 1", "item 2", "item 3");
echo csv($a); // Output: "item 1","item 2","item 3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment