Personal how to go through an array with multiple requests?

Asked

Viewed 87 times

0

I am receiving this object via API and would need to scroll through each of these pages, remembering that each page is a request. Here in this demonstration I am on page 1 each page brings me 50 records and the return shows me that there are 39 pages.. how do I go through these 39 pages making a request to each page? Since I am very grateful for the help of all.

Array
(
[retorno] => Array
    (
        [status_processamento] => 3
        [status] => OK
        [pagina] => 1
        [numero_paginas] => 39
        [contas] => Array
            (
                [0] => Array
                    (
                        [conta] => Array
                            (
                                [id] => 504024714
                                [nome_cliente] => IRINEU DOMINGOS ANTUNES
                                [historico] => CONTAS A PAGAR - (Cliente sistema antigo - incluso no SCPC)
                                [numero_banco] => 
                                [numero_doc] => 000022554
                                [serie_doc] => 0
                                [data_vencimento] => 10/12/2014
                                [situacao] => aberto
                                [data_emissao] => 28/11/2017
                                [valor] => 392.66
                                [saldo] => 392.66
                            )

                    )

                [1] => Array
                    (
                        [conta] => Array
                            (
                                [id] => 503982261
                                [nome_cliente] => MARCUS VINICIUS DE OLIVEIRA CUNHA
                                [historico] => Ref. Venda otica self care Elisama
                                [numero_banco] => 
                                [numero_doc] => 000270860
                                [serie_doc] => 0
                                [data_vencimento] => 27/02/2015
                                [situacao] => aberto
                                [data_emissao] => 28/11/2017
                                [valor] => 444.00
                                [saldo] => 444.00
                            )

                    )

                [2] => Array
                    (
                        [conta] => Array
                            (
                                [id] => 503885902
                                [nome_cliente] => LUIZ CARLOS MIRANDA
                                [historico] => CONTAS A RECEBER - PEDIDO 5912 - LUIZ CARLOS MIRANDA - Parcela (1/8)
                                [numero_banco] => 
                                [numero_doc] => 000005912
                                [serie_doc] => 0
                                [data_vencimento] => 14/01/2016
                                [situacao] => aberto
                                [data_emissao] => 27/11/2017
                                [valor] => 125.00
                                [saldo] => 125.00
                            )

                    )

                [3] => Array
                    (
                        [conta] => Array
                            (
                                [id] => 503885904
                                [nome_cliente] => LUIZ CARLOS MIRANDA
                                [historico] => CONTAS A RECEBER - PEDIDO 5912 - LUIZ CARLOS MIRANDA - Parcela (2/8)
                                [numero_banco] => 
                                [numero_doc] => 000021248
                                [serie_doc] => 0
                                [data_vencimento] => 13/02/2016
                                [situacao] => aberto
                                [data_emissao] => 27/11/2017
                                [valor] => 125.00
                                [saldo] => 125.00
                            )

                    )

                [4] => Array
                    (
                        [conta] => Array
                            (
                                [id] => 503991231
                                [nome_cliente] => WELLIGTON RODRIGO RIBEIRO DA SILVA
                                [historico] => CONTAS A RECEBER - PEDIDO 1452 - WELLIGTON RODRIGO RIBEIRO DA SILVA - Parcela (1/10)
                                [numero_banco] => 
                                [numero_doc] => 000001452
                                [serie_doc] => 0
                                [data_vencimento] => 13/02/2016
                                [situacao] => aberto
                                [data_emissao] => 28/11/2017
                                [valor] => 30.00
                                [saldo] => 30.00
                            )

                    )

1 answer

1

Run a foreach at each level of the array.

foreach($retornoDaAPI['retorno'] as $key => $value){
    foreach($value['contas'] as $key2 => $value2){
       //e assim sucessivamente
    }
}
  • Thank you very much for your reply, Mr Fabre. Example when I make a request I have a return with 50 registrations per page until you are cool I can walk smoothly through the array. only api sends me separate all records in a total of 39 pages. ie are 39 requests I have to make... but how to do? remembering that I inform a parameter at the url stating which page I want to get ex &pagina=5, at the request url. but I want to know if there’s a way to go through all these pages in a single called the api.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.