Skip to content
Advertisement

Brackets instead of comma using foreach to create JSON with PHP

So I’m trying to create an open source file manager with php using ajax requests and, when i use json_encode my json response gets a close bracket for each array key.

This is the code (PHP):

JavaScript

and this is the result:

JavaScript

and i need this result

JavaScript

Advertisement

Answer

You encode to quickly. Try this:

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