I have a multi-dimensional array which I fill via $.each
$('.gBook').click(function(){
var values = [];
var valueToPush = { }; // or "var valueToPush = new Object();" which is the same
var i = 0;
$('td[data-check="true"]').each(function(){
valueToPush["price"] = $(this).attr("data-price");
valueToPush["id"] = $(this).attr("data-id");
values.push(valueToPush);
i++;
});
var arrayToSend = {values};
$.post( '<?php echo PATH;?>ajax/updateRoom.php',values, function(data){
if(data != "ERROR"){
$('#all-content').html(data).css("overflow-y","auto");
}else{
alert("ERROR");
}
});
});
But the outcome is the same for all POST vars:
Array (
[values] => Array (
[0] => Array ( [price] => 15 [id] => 3380 )
[1] => Array ( [price] => 15 [id] => 3380 )
[2] => Array ( [price] => 15 [id] => 3380 )
)
)
Where is my mistake? It seems that "push" overrides everytime?
valueToPushinside theeachfunction, you are pushing the same object "pointer" invalueseach time the function is executed (and updating these values)iat all