In this question, I had help in simplifying and forming a valid complicated JSON POST request. However, I’ve now encountered some odd behavior server-side.
function postTour(){
$post = json_decode($_POST['json'];
$success = false;
for ($i=0; $i<count($post); $i++){
$filename = $post[i]['location']['filename'];
}
}
Here, $filename is never initialized and never shows up as a variable in the debugger. $post returns a multi-level array of the format
$post[3]
[0] =>
location = [ 5 key/value pairs ]
links = one to n arrays
[1] =>
location = [ 5 key/value pairs],
links = one to n arrays
In the debugger, each outermost array and location array has the type stdClass, while the links array has the type array[n]. However, I can’t access any information inside $post. Why is this?
try passing
trueas a second argument tojson_decode()in order to convert it to an actual array.