I'm having some trouble sending multidimensional array [N][N] from javascript to PHP, I already tried alot of solutions that I'd found here but I don't know what I'm doing wrong.
My JQuery code (saving values from a HTML table):
$rowArray = {};
for ($i = 0; $i < $myRows.length; $i++) {
$row = $($myRows[$i]).find('td');
$rowArray[$i] = {};
for ($j = 0; $j < $row.length - 1; $j++) {
$rowArray[$i][$j] = $($row[$j]).html();
}
}
Then:
$myJsonString = JSON.stringify($rowArray);
$.ajax({
type: "POST",
url:"../../download/myStore.php",
data: { table: $myJsonString },
success: function(data){
console.log(data);
}
});
PHP Side:
echo $_POST['table']; //just to see what is coming, but i want to work as array
//$data = json_decode($_POST['table'],true); -> when I echo $data, the output is an error Array to String conversion
Output:
{"0":{"0":"Cadastrado em","1":"Data da Venda","2":"Empreendimento","3":"Bloco/<br>Unidade","4":"Cliente/<br>Parceiro","5":"Valor","6":"Filial","7":"Gerente","8":"Corretor","9":"Veículo"},"1":{"0":"27/04/2016","1":"11/04/2016","2":"Villa Flora Hortolândia - Cond. 06","3":"Bloco/Torre: 13, Unidade: 283","4":"Lidiane Sasaki Santana","5":"20.664.259","6":"Campinas","7":"NATAL","8":"WILLIAM PILOTO","9":"Internet"},"2":{"0":"12/04/2016","1":"12/04/2016","2":"Lifespace Curitiba","3":"Bloco/Torre: 1, Unidade: 2404","4":"ANA","5":"351.000","6":"Curitiba","7":"André Barbosa de Lima","8":"Daniele","9":"Google"},"3":{"0":"12/04/2016","1":"12/04/2016","2":"ROSSI ATUAL MORADA","3":"Bloco/Torre: 3, Unidade: 407","4":"BERNADETE STARKE","5":"245.000","6":"Curitiba","7":"André Barbosa de Lima","8":"Dranka","9":"Google"},"4":{"0":"12/04/2016","1":"12/04/2016","2":"Lifespace Curitiba","3":"Bloco/Torre: 2, Unidade: 1105","4":"FLAVIA AMARAL","5":"272.500","6":"Curitiba","7":"André Barbosa de Lima","8":"Jesus","9":"Yahoo"},"5":{"0":"12/04/2016","1":"12/04/2016","2":"Lifespace Curitiba","3":"Bloco/Torre: 2, Unidade: 1809","4":"itajana","5":"270.500","6":"Curitiba","7":"André Barbosa de Lima","8":"Daniele","9":"Site Rossi"},"6":{"0":"27/04/2016","1":"14/04/2016","2":"Villa Flora Hortolândia - Cond. 05","3":"Bloco/Torre: 5, Unidade: 41","4":"Andre Fernando Da Silva Gradino","5":"184.303","6":"Campinas","7":"NATAL","8":"TIAGO","9":"Cadastro Manual"}}
How can I access each index inside each array to get my values?
Whenever I try to use an index like $_POST['table'][0] the output is just '{'.
Sorry for my english and sorry for this noob question, but I'm stucked here for hours and already tried alot of solution found here and on google.