Skip to content
Advertisement

how to create a json array with data from a foreach loop in php

i have some json files which look like this:

JavaScript

To read all the json files in a dir i use this code (process.php):

JavaScript

My jquery ajax looks like this:

JavaScript

I do not receive the data from the foreach loop. What is going wrong?

Advertisement

Answer

First of all, you’re overwriting your result in the loop constantly. You need to create a new array element within data in the loop.

JavaScript

Secondly, since you’re not changing anything in your loop, you could just use your $objs array and remove the loop. The loop doesn’t do anything in your example.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement