Codice PHP:
<?php
$rows = 4;
$cols = 15;
$matrix2 = array(
array(2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
array(0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0),
array(0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 0),
array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0),
array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 5)
);
$accumolo = '';
for($i = 0; $i <= $rows; $i++) {
for($j = 0; $j <= $cols; $j++) {
if($j==$cols) {
$pezzo=$matrix2[$i][$cols];
$accumolo .= $pezzo;
if($i!=$rows){
$accumolo .= "\n";
}
} else {
$accumolo .= $matrix2[$i][$j].',';
}
}
}
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo $accumolo;
?>