Skip to content
Advertisement

Format the json encode just like on laravel php

Supposed I have a query that gets the image from a certain tweet

JavaScript

And I have a result also from a query that gets all of the tweet

JavaScript

How can I format the result like this (Just like on laravel)

JavaScript

And this is my simplified code

JavaScript

but it just gives me the following output

JavaScript

Any idea how can I format the result. thanks in advance.?

Advertisement

Answer

I’m not sure what’s troubling you but in order to add multiple values inside, just put another nesting like what I’ve eluded in the comments section:

JavaScript

So to complete the answer:

JavaScript

This essentially creates another dimension for pics index as an array and continually pushing, provided they have the same ID.

Sidenote: tweet_id is to pics and id is to aTweets. Your’s have the other way around.

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