Skip to content
Advertisement

PHP Encoding JSON Issue

I wanna json encode a PHP array to send it for a server, but the server wants it in this format:

JavaScript

But now my associative array after using json_encode() on it looks like this:

JavaScript

Advertisement

Answer

The first version with the [] is an array of objects, you just have a single object. Just create an array with that single object…

JavaScript

gives…

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