After you run your script (assuming 01523
in your array is actually the string "01523"
), the contents of demosaved.csv will be:
"Column 1","Column 2","Column 3","Column 4","Column 5"
01523,"Data 12","Data 13","Data 14","Data 15"
If you open it in a text editor, you will see the leading zero, because it is there in the file. If you open it in Excel, you will not see the leading zero, even though it is there in the file, because that's how Excel displays numbers with leading zeroes.
Even if you edit your demosaved.csv file in your text editor and put quotes around the number with the leading zero, so it's "01523","Data 12"...
instead of 01523,"Data 12",...
, Excel will still not display the leading zero. The only way to force Excel to display the leading zero in a number in a CSV file is to use one of the tricks you want to avoid.
If the intended use of your output file is to be opened in Excel, you can create an Excel document instead of a CSV file. Here's a quick example with PhpSpreadsheet:
<?php
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->fromArray($data, null, 'A1');
$writer = new Xlsx($spreadsheet);
$writer->save('example.xlsx');
The leading zero will show up in example.xlsx. But this file format cannot be used to pass your data to another application that expects a CSV. If that is the intended use of your output file, the way you're already doing it is fine.
However, if you do open the CSV in Excel, edit it (or not), and save the changes, the leading zero will be gone.