Browse PHP Array

0

I have the following call to a model '

$dados = $this->atleta_model->get_atividade_semanal($__cod);

But it is returning an object that I can not iterate, I have to go through it to put its values in a table.

Return of the model

array(1) {
    [0]=> object(stdClass)#26 (4) { 
        ["cod_atleta_ativ_sem"]=> string(3) "164" 
        ["dia_semana"]=> string(5) "Sexta" 
        ["data_hora"]=> string(16) "09/11/2018 15:35" 
        ["descricao"]=> string(5) "Teste" 
    } 
}

I'm trying to go through it as follows.

 while ($relatorio=$dados->fetch_assoc()) { 

    $content .= "
        <tr>
            <td>".$relatorio["cod_atleta_ativ_sem"]."</td>
            <td>".$relatorio["cod_atleta"]."</td>
            <td>".$relatorio["data_hora"]."</td>
            <td>".$relatorio["descricao"]."</td>
            <td>".$relatorio["data_alteracao"]."</td>
            <td>S/. ".$relatorio["usuario_alteracao"]."</td>
        </tr>
    ";
    }
    
asked by anonymous 09.11.2018 / 19:35

1 answer

1

As this is a StdClass, you can convert to array just by passing the (array) in front:

foreach($dados as $relatorio){
    $relatorio = (array)$relatorio;

    ...
}
    
09.11.2018 / 19:47