Skip to content
Advertisement

One-liner to fetch data in a loop / iterator and store into a variable

Is there some magic one-liner to get this data ?

JavaScript

Not while ($res->next()) $this->data['DwellingUnit'][] = $res->row;

Advertisement

Answer

I presume iterator_to_array can be used with array_column:

JavaScript

As array_column can extract values from array of objects too, but since php7.

As a con: here’re two loops – one over iterator to get an array, second is over array to extract row property.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement