Return amount of PHP Array responses

2

I have the following array ():

Array
(
    [0] => stdClass Object
        (
            [men_id] => 3
            [usu_id] => 2
            [usu_destino] => 2
            [id_resposta] => 0
            [usu_respondeu] => 0
            [set_assunto] => 147
            [men_mensagem] => Tese 03
            [men_data] => 2017-11-05 16:02:39
            [men_data_lida] => 0000-00-00 00:00:00
            [men_resposta] => 1
            [men_status] => 1
            [total_respostas] => 1
        )

    [1] => stdClass Object
        (
            [men_id] => 21
            [usu_id] => 2
            [usu_destino] => 3
            [id_resposta] => 0
            [usu_respondeu] => 0
            [set_assunto] => 147
            [men_mensagem] => Teste de Envio de Mensagem
            [men_data] => 2017-11-05 19:30:38
            [men_data_lida] => 0000-00-00 00:00:00
            [men_resposta] => 1
            [men_status] => 1
            [total_respostas] => 0
        )

    [2] => stdClass Object
        (
            [men_id] => 22
            [usu_id] => 2
            [usu_destino] => 2
            [id_resposta] => 0
            [usu_respondeu] => 0
            [set_assunto] => 147
            [men_mensagem] => Apenas enviar um email para o dom Jose da Silva, [email protected]
            [men_data] => 2017-11-05 19:31:43
            [men_data_lida] => 0000-00-00 00:00:00
            [men_resposta] => 1
            [men_status] => 1
            [total_respostas] => 1
        )

)

I need to return a count () of all those with total_responses = 0. How can I do it?

    
asked by anonymous 19.11.2017 / 13:57

1 answer

3

First you must filter the items of array to bring only what you need that in your case in specific is total_respostas == 0 then use count to count the amount returned, example :

$total = count(array_filter($array, function($q){
    return $q->total_respostas == 0;
}));

19.11.2017 / 14:34