To create the contents of a JSON
file, first we create a array
:
$meus_dados = array();
Once we have a array
created we should array
:
for ($i = 0; $i < 3; $i++) {
$meus_dados[$i]['nome'] = "nome".($i + 1);
$meus_dados[$i]['email'] = "email".($i + 1);
$meus_dados[$i]['id'] = "id".($i + 1);
}
Now that we already have our array
populated, we have to use the json_encode
function to generate a JSON
of that array
:
echo json_encode($meus_dados);
Result
[{"name": "name1", "email": "email1", "id": "id1"},
{"name": "name2", "email": "email2", "id": "id2"},
{"name": "name3", "email": "email3", "id": "id3"}]