I am trying to create a data analytics portal which allows me to export one of my tables as CSV. The problem I have now is that when a user selects a huge range of data, it fails because it has reached the maximum stack size for Javascript variables available to my browser. (As explained here). The solution is to split them into smaller Javascript array chunks and then concatenate them again later.
My problem
I have a big PHP array (of variable size because I wont know what range the user selects) and I need to split them into a variable number of Javascript arrays and then concatenate them again later. How can I achieve that?
My code currently looks like that
<?php
$array2 = getAllRawData($startDate, $endDate, $merchantID);
array_unshift($array2, ...TO ADD HEADER TO CSV....));
?>
// I am thinking some magic is supposed to happen here that splits my PHP array into smaller parts, assign them to javascript arrays and then concatenate them together into items2.
var items2 = <?php echo json_encode($array2);?>; // this is what I currently do but fails when the date range gets too wide.
var jsonObject2 = JSON.stringify(items2);
var csv2 = ConvertToCSV(jsonObject2);
a=document.createElement('a');
a.textContent='Download Raw Waiting Time Report';
a.download="RawWaitTime.csv";
a.href='data:text/csv;charset=utf-8,'+escape(csv2);
document.body.appendChild(a);