Hey guys
Im trying to convert a yii model into an array. And then that bidimentional array into a single array.
I use this code to make a yii model into a bidimentional array .
$items = \app\models\Poblacion::find()
->select(['municipio', 'poblacion'])
->asArray()
->all();
Which return the following array
Array (
[0] => Array ( [municipio] => Total de la entidad Michoacán de Ocampo [poblacion] => 4351037 )
[1] => Array ( [municipio] => Acuitzio [poblacion] => 10987 )
[2] => Array ( [municipio] => Aguililla [poblacion] => 16214 )
[3] => Array ( [municipio] => Álvaro Obregón [poblacion] => 20913 )
)
Then I use this code to make the bidimentional array into a unidimentional array
$res = array();
foreach($items as $k =>$v){
foreach($v as $t)
$res[] = $t;
}
Which return this:
Array (
[0] => Total de la entidad Michoacán de Ocampo
[1] => 4351037
[2] => Acuitzio
[3] => 10987
[4] => Aguililla
[5] => 16214
[6] => Álvaro Obregón
[7] => 20913
)
but that’s not what I need. I need somthing like this.
Array (
[Total de la entidad Michoacán de Ocampo] => 4351037
[Acuitzio ] => 10987
[Aguililla ] => 16214
[Álvaro Obregón] => 20913
)
Do you have any idea??? I hope you can help me.