How to structure data for JSON with PHP

0

I have the return of a query that brings me the following items from the following query (NOTE: they are tables created for examples)

 select * from alunos a left join financs f on f.aluno_id = a.id left join financ_detalhes fd on fd.financ_id = f.id

WhatIwanttodoisstructurethisforjsonfromphpsoitlookslikethis:

{"aluno": [
    {
      "id": "1",
      "nome": "felipe",
      "nr_cpf": "11111",
      "situação": "A",
      "financeiro": [
        {
          "id": "1",
          "dt_pag": "2018-04-10",
          "situacao": "p",
          "descricao": [
            {
              "id": "1",
              "descricao": "olá chefe"
            },
            {
              "id": "2",
              "descricao": "olá jurubeba"
            }
          ]
        },
        {
          "id": "2",
          "dt_pag": "2018-04-10",
          "situacao": "p",
          "descricao": []
        }
      ]
    },
    {
      "id": "2",
      "nome": "jose",
      "nr_cpf": "2222",
      "situação": "A",
      "financeiro": [
        {
          "id": "1",
          "dt_pag": "2018-04-10",
          "situacao": "p",
          "descricao": []
        }
      ]
    }
  ]
}

I've tried every possible way but I can not, does anyone have any tips or know how I can do it?

Moment where I gave up temporarily:

 foreach($alunosBase as $index=>$aluno) {

   $financeiroDesc[$index][] = ['detalhes_id' => $aluno['detalhes_id'],'detalhes_descricao' => $aluno['detalhes_descricao']];

    if(!in_array($aluno['id_financ'],$mapRegFinan)) {
       $financeiro[$index][] = ['id_financ' => $aluno['id_financ'], 'dt_pag'=> $aluno['dt_pag']];
       $mapRegFinan['id_financ'] = $aluno['id_financ'];
    }

}
    
asked by anonymous 10.04.2018 / 19:24

0 answers