Skip to content
Advertisement

PHP – json_encode

I generate json files manually this way:

JavaScript

Someone help me create the function json_encode? I tried in different ways to add variables to the array, but every time I have something different on the output.

Output: https://pastebin.com/f8keXaY7

Advertisement

Answer

First Step : Build your json structure in a php array and store it in a variable.

Something like that.

JavaScript

Second Step : Use json_encode function.

JavaScript

And, If your output is always different, it means that your input is always different.

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