I need to create a json document, with the following structure:
[
{
"Name": "Lacy",
"Email": "[email protected]"
},
{
"Name": "Chancellor",
"Email": "[email protected]"
}]
Currently, I have the following array:
array (size=10)
0 =>
array (size=3)
'id' => string '1' (length=1)
'nome' => string 'Lacy' (length=35)
'email' => string '[email protected]' (length=20)
1 =>
array (size=3)
'id' => string '2' (length=1)
'nome' => string 'Chancellor' (length=25)
'email' => string '[email protected]' (length=25)
And to try to turn it into the result I want, I have the following code:
$arrayClientes = array();
for($i=0; $i<count($clientes); $i++){
array_push($arrayClientes, array("Nome"=>$clientes[$i]['nome'], "Email" => $clientes[$i]['email']));
}
echo '<pre>';
echo json_encode($arrayClientes);
echo '<pre>';
In this way, it does not echo
of $arrayClientes
.
How can I create a Json array like that?