I know this question has been asked a few times here, but all of the solutions won't work when I tried them, so here is the question once more.
I have a pretty big javascript array with integers between -10 and 10. I want to save those in a database so I have to sent them to php using the jquery $.post function. However the array is to big, so I converted the array to a string in javascript, but I want to convert it back to an array of integers in php. How can I do this? This is my code
function updateDb(){
for(i = 0; i < inputSquares.length; i++) {
for(j = 0; j <= 9; j++) {
perceptronsWeights[10*i+j] = inputSquares[i].weights[j]
};
};
var pws = String(perceptronsWeights);
alert(typeof pws);
$.post("updateDatabase.php", {size: size, weights:pws}).done (
function(data) {
alert (data);
}
)
}
And in my php file I use:
$weightsString = $_POST['weights'];
$pws = array_map("intval", explode(",", $weightsArray));
echo $pws;
I have also tried explode() without array_map and str_split but both of them give me this error:
Notice: Array to string conversion in C:\xampp\htdocs\ANN_JS\updateDatabase.php on line 19
Array
(line 19 is echo $pws;)
if anyone knows a solution, please let me know :)
Aucun commentaire:
Enregistrer un commentaire