Browse the PHP Array

Asked

Viewed 64 times

0

I have the following call for a model`

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

However it is returning me an object that I cannot iterate, I need to go through it to put its values in a table.

Model return

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 walk through it this way.

 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>
    ";
    }

1 answer

1


Since it is a Stdclass, you can convert to array just by passing the (array) in front:

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

    ...
}

Browser other questions tagged

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