Formatting stdClassObject for array

3

I have a problem converting some data to my system, I have the following code snippet that returns an array with a few objects:

Array(
    [4014] => stdClassObject([id] => 4014[registro] => 9877[sigla] => total)
    [4006] => stdClassObject([id] => 4006[registro] => 9877[sigla] => Parcial)
)

I need to convert these objects to an array to send to a webservice where the webservice pattern is described below:

Final Objective:

Array(
    [lista] => Array(
        [0] => Array(
            [registro] => 7069[sigla] => Parcial
        ) [1] => Array(
            [registro] => 7069[sigla] => Total
        ) 
    )
)

What I was able to implement was this:

$dados = $DB->return_records($query);
foreach($dados as $dado) {
   $listagem['lista'][]= $dado;
}

And has returned the following excerpt:

Array(
    [lista] => Array(
                    [0] => stdClassObject([id] => 4014[registro] => 9877[sigla] => total)
                    [1] => stdClassObject([id] => 4006[registro] => 9877[sigla] => parcial)
                )
    )

Now I'm trying to generate the result of block 2, but I still can not, could anyone help me?

    
asked by anonymous 04.08.2016 / 17:06

1 answer

5

Do so, you must do the cast of each obj for array :

$dados = $DB->return_records($query);
foreach($dados as $dado) {
   $listagem['lista'][] = (array) $dado;
}
    
04.08.2016 / 17:09