I'm trying to save a multidimensional Javascript array as a CSV file on the server. So far, my code creates the CSV file, but the file doesn't contain my array, and I'm not sure why.
(where outputData is established)
function dataSave(){
outputStr = JSON.stringify(outputData);
$.ajax({
type: "POST",
url: "csvout.php",
data: outputStr,
dataType: 'html',
});}
csvout.php:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<?php
$array = json_decode($_POST['outputStr']);
$file = fopen("out/data.csv","w");
foreach ($array as $line){
foreach ($line as $item){
fputcsv($file,explode(',',$item));
}
}
fclose($file);
?>
</head>
<body>
</body>
</html>
The data is an array of arrays like this one-- it's data obtained from the client, who is participating in a scientific experiment. Everything is a string.
0: "tuba.mp3"
1: "prac"
2: "1"
3: "0"
4: "type1"
5. "500"
0: "clap.mp3"
1: "main"
2: "0"
3: "0"
4: "type1"
5. "300"
[...]
var_dump($array)after you've assigned it in PHP and update your question with the result (or a summary of the result, I need to know how deep the array is).