I am using json_encode to create a JSON object from an array. They array is a couple hundred elements long, but json_encode appears to only give back the first element of the array.
Is this a limitation of json_decode, or am I using the wrong syntax to read the JSON object?
A little code:
I create the array in PHP:
$getarrayforjson = mysql_fetch_array($result);
And in the javascript, I made it a variable:
var my_array = <?php echo json_encode($getarrayforjson); ?>
Typing ‘my_array’ in the console gives me a nice JSON-looking response, but only for the first element.
When I use the JSON in the code, like my_array.title, or my_array[4], I always get the same result.
I think my syntax is wrong, but am not sure how to fix it. I’m new to using json_encode.
That is only one result. Try this: