Ciao a tutti, ho bisogno di un vostro aiuto. Devo creare un array "complesso" per poi poterlo convertirlo in json. Attualmente ho sempre fatto in questo modo:
Restituendo un file json cosi:Codice PHP:
//Prelevato i dati da un db mysql
$event_array[] = array( 'id' => $record['id'], 'nome' => $record['nome'],
'cognome' => $record['cognome'],
'citta' => $record['citta']
);
echo json_encode($event_array);
[{
"id": 1,
"nome": 'Nicola',
"cognome": 'Rossi',
"citta": 'Roma'
}]
Io vorrei creare una cosa del genere:
{
"posts": [
{
"id": 1,
"title": "Post 1"
},
{
"id": 2,
"title": "Post 2"
},
{
"id": 3,
"title": "Post 3"
}
],
"comments": [
{
"id": 1,
"body": "some comment",
"postId": 1
},
{
"id": 2,
"body": "some comment",
"postId": 1
}
],
"profile": {
"name": "typicode"
}
}
Grazie