0

I'm trying to get data from an object that arrives as json, I transform it into an array of objects and look for the amount of array within a value. With that, I need to know which is the newest array within this array.

Example:


Array
(
    [response] => Array
        (
            [0] => Array
                (
                    [canalAtendimento] => URA
                    [IdentificadorParceiroNegocio] => 
                    [IdentificadorInstalacao] => 7008000000
                    [Ani] => 21981737137
                    [DataInicio] => 
                    [HoraInicio] => 
                    [DataFim] => 04/05/2021
                    [HoraFim] => 09:42:25
                    [Dnis] => 
                    [MenuAtend] => 
                    [DocCliente] => 
                    [EnderecoVocalizado] => 
                    [Protocolo] => 
                    [GuidProtocolo] => 
                    [IdentificacaoNotaServico] => 
                    [Funcionalidade] => 
                    [Descricao] => 
                    [Usuario] => 
                    [NsDetails] => 
                    [created] => 04/05/2021 09:39:15
                )

            [1] => Array
                (
                    [canalAtendimento] => URA
                    [IdentificadorParceiroNegocio] => 
                    [IdentificadorInstalacao] => 7008000000
                    [Ani] => 21981737137
                    [DataInicio] => 04/05/2021
                    [HoraInicio] => 09:43:00
                    [DataFim] => 04/05/2021
                    [HoraFim] => 09:45:14
                    [Dnis] => 
                    [MenuAtend] => 
                    [DocCliente] => 
                    [EnderecoVocalizado] => 
                    [Protocolo] => 
                    [GuidProtocolo] => 
                    [IdentificacaoNotaServico] => 
                    [Funcionalidade] => 
                    [Descricao] => 
                    [Usuario] => 
                    [NsDetails] => 
                    [created] => 04/05/2021 09:42:01
                )

            [2] => Array
                (
                    [canalAtendimento] => URA
                    [IdentificadorParceiroNegocio] => 
                    [IdentificadorInstalacao] => 7008000000
                    [Ani] => 21981737137
                    [DataInicio] => 04/05/2021
                    [HoraInicio] => 10:15:51
                    [DataFim] => 04/05/2021
                    [HoraFim] => 10:16:25
                    [Dnis] => 
                    [MenuAtend] => 
                    [DocCliente] => 
                    [EnderecoVocalizado] => 
                    [Protocolo] => 
                    [GuidProtocolo] => 
                    [IdentificacaoNotaServico] => 
                    [Funcionalidade] => 
                    [Descricao] => 
                    [Usuario] => 
                    [NsDetails] => 
                    [created] => 04/05/2021 10:13:12
                )

            [3] => Array
                (
                    [canalAtendimento] => URA
                    [IdentificadorParceiroNegocio] => 
                    [IdentificadorInstalacao] => 7008000000
                    [Ani] => 21981737137
                    [DataInicio] => 04/05/2021
                    [HoraInicio] => 10:36:21
                    [DataFim] => 04/05/2021
                    [HoraFim] => 10:37:31
                    [Dnis] => 
                    [MenuAtend] => 
                    [DocCliente] => 
                    [EnderecoVocalizado] => 
                    [Protocolo] => 
                    [GuidProtocolo] => 
                    [IdentificacaoNotaServico] => 
                    [Funcionalidade] => 
                    [Descricao] => 
                    [Usuario] => 
                    [NsDetails] => 
                    [created] => 04/05/2021 10:34:43
                )

        )

)

I have 4 arrays inside the array response. 0, 1, 2 and 3. in this example the 3 is the newest according to DataFim and HoraFim, but the data can come random. so I needed to know how to get the last array according to DataFim and HoraFim.

Any ideas on how to do this?

If performing the query directly with the json result is better, I accept suggestions.

Rafael
  • 11
  • 2

1 Answers1

0

You need a select query using group by DataFim and HoraFim and order by desc limit 1 , like this you can select the most new array

Example of a query using group by and order by desc

"Select * from table_club Group by DateFim , HoraFim Order By DateFim,HoraFim Desc limit 1"
Fares Ben Slama
  • 93
  • 4
  • 15
  • The question has nothing to do with SQL. – IMSoP May 04 '21 at 15:19
  • using this query in PHP solves the problem , the result of the query must give the most new array – Fares Ben Slama May 04 '21 at 15:21
  • in this case you need a filter method that filters by DateFim and HoraFim – Fares Ben Slama May 04 '21 at 15:24
  • sorry i was trying to help – Fares Ben Slama May 04 '21 at 15:32
  • Sorry is not a SQL, the reult came in json.it is a rest api that I consult and return to me in json. This value in json is returned as follows: `{"response":[{"canalAtendimento":"URA","DataFim":"04\/05\/2021","HoraFim":"09:42:25",...},{"canalAtendimento":"URA",...}]}` and i need to know which is the newest object to get the values from only the newest object. – Rafael May 04 '21 at 15:38