I am sending JSON to a PHP script. I do this through jQuery ajax call. I think the ajax part works quite well. But here is the code I'm using:
var testjson = '{"statistics":[{"player_id":"12","team_id":"8","points":"19"},{"player_id":"9","team_id":"8","points":"7"}],"teams":[{"homename":"Lakers","awayname":"Heat","webid":"48","hid":"49","aid":"48"}]}'; function postGameStats() { jQuery.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "ajax-url.php", data: {"data":JSON.stringify(testjson)}, success : function(data){ alert(data); } }); }
In my PHP page, I want to skip decoded JSON and save the data in my db. As soon as I get the values ββfrom the array, I can save them. But I can not get them out of the array at the moment! I cannot find an explanation of access to a multidimensional array in PHP that I can understand. Here is my PHP:
$finally = json_decode($_POST['data'], true); $size = count($finally[1]); $i = 0; while ($i < ($size)) { echo $finally[$i].['statistics'].[$i].['player_id']; $i = $i + 1; }
Can someone point me in the right direction to access values ββfrom an array? Thanks for that in advance!
source share