1
I need the following result:
{
"sala": [{
"horario": "18:30",
"data": "Seg e Terça"
}, {
"horario": "10:30",
"data": "Quarta Terça"
}]
}
UPDATE
I’m doing it like this in PHP:
/*criando objeto vazio*/
$object = new stdClass();
/*passando array para o objeto vazio*/
$object->salas = array();
$quantidade= $_POST['quantidade'];//imagina que aqui tem 2
for($i=0;$i<count($quantidade);$i++){ //aqui vai rodar 2x
$horario = $_POST['horarios_'.$quantidade]; //ATUALIZAÇÃO
$dias= $_POST['dias_'.$quantidade]; //ATUALIZAÇÃO
/*percorrendo o objeto vazio*/
foreach ($object as $key => $value) {
$object_data = new stdClass();
$object_data->horario = $horario;//valor da hora
$object_data->data = $dias;//valor do dia
array_push($object->salas, $object_data);
}
/*codificando json*/
echo json_encode($object);
}
But I’m getting it wrong:
{
"salas": [{
"horario": ["18:30", "10:30"],
"data": ["Seg e Terça, Quarta Terça"]
}]
}
Once I can generate the correct structure, how can I print the information according to each schedule and date
It’s nothing sorry I think I’ve got it, sorry
– Miguel
Okay. Give to help?
– Lollipop
I tested it on ideone and it worked check it out https://ideone.com/j1qgjT
– Neuber Oliveira
Right, but when there’s more than one value to insert into
$object_data->horario
and$object_data->data
, give this last json of the question, I think it is on account of the foreach that involves it, how to solve?– Lollipop
How you got the data originally?
– Miguel
clears the $object_data variable at the end of foreach. unset($object_data)
– Euler01
@Euler01 I think that is not the problem, because at the beginning of the foreach already has
$object_data = new stdClass();
then it starts clean right?. @Lollipop put like this the array of "out".– Neuber Oliveira
Guys, I updated and put the
for
to better understand andPOST
to value the variables.– Lollipop
@Neuberoliveira already had a problem similar to this, which I solved by cleaning the variable. Since then I test everything. kkkkk
– Euler01
@Euler01, nothing yet :(
– Lollipop