4
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>';
This way, he doesn’t do the echo
of $arrayClientes
.
How can I create a Json array like those?
I already solved it. The problem was not in the array, but in the data it received. I had to make utf8_encode to the name that came in the array.
– user3587262