model returns numeric array into string array

Hello guys I need your help

I have a DB with int values. But my model returs all that numbers into string type. Something lik this


array(4) { [3]=> array(12) { [0]=> string(1) "2" etc....

What I need is the data to be int type. I dont know what’s going on.

This is to get data in model file.


public function getMunAI($val,$anio) {    

        $param=$anio-5;

        $sql = 'select anio_id, SUM(ene) as enero,sum(feb)as febrero, sum(mar) as marzo,sum(abr) as abril, sum(may) as mayo, sum(jun) as junio, sum(jul) as julio, sum(ago) as agosto,sum(sep) as septiembre, sum(oct) as octubre, sum(nov) as noviembre, sum(dic) as diciembre from seisp.incidencia where municipio_id=:munchen and  anio_id>:year  group by anio_id asc';

        $sqlvio = 'select anio_id, SUM(ene) as enero,sum(feb)as febrero, sum(mar) as marzo,sum(abr) as abril, sum(may) as mayo, sum(jun) as junio, sum(jul) as julio, sum(ago) as agosto,sum(sep) as septiembre, sum(oct) as octubre, sum(nov) as noviembre, sum(dic) as diciembre from seisp.incidencia where municipio_id=:munchen and modalidad_id=2 and  anio_id>:year   group by anio_id asc';

        $sqlhd = 'select anio_id, SUM(ene) as enero,sum(feb)as febrero, sum(mar) as marzo,sum(abr) as abril, sum(may) as mayo, sum(jun) as junio, sum(jul) as julio, sum(ago) as agosto,sum(sep) as septiembre, sum(oct) as octubre, sum(nov) as noviembre, sum(dic) as diciembre from seisp.incidencia where municipio_id=:munchen and modalidad_id=3 and tipo_id=10 and  anio_id>:year    group by anio_id asc';

        $sqlnm = 'select anio_id, SUM(ene) as enero,sum(feb)as febrero, sum(mar) as marzo,sum(abr) as abril, sum(may) as mayo, sum(jun) as junio, sum(jul) as julio, sum(ago) as agosto,sum(sep) as septiembre, sum(oct) as octubre, sum(nov) as noviembre, sum(dic) as diciembre from seisp.narcomenudeo where municipio_id=:munchen and anio_id>:year    group by anio_id asc';

        $sqlsec = 'select anio_id, SUM(ene) as enero,sum(feb)as febrero, sum(mar) as marzo,sum(abr) as abril, sum(may) as mayo, sum(jun) as junio, sum(jul) as julio, sum(ago) as agosto,sum(sep) as septiembre, sum(oct) as octubre, sum(nov) as noviembre, sum(dic) as diciembre from seisp.incidencia where municipio_id=:munchen and modalidad_id=6  and  anio_id>:year    group by anio_id asc';

        $sqlrch = 'select anio_id, SUM(ene) as enero,sum(feb)as febrero, sum(mar) as marzo,sum(abr) as abril, sum(may) as mayo, sum(jun) as junio, sum(jul) as julio, sum(ago) as agosto,sum(sep) as septiembre, sum(oct) as octubre, sum(nov) as noviembre, sum(dic) as diciembre from seisp.incidencia where municipio_id=:munchen and subtipo_id=6 and  anio_id>:year    group by anio_id asc';

        $sqlran = 'select anio_id, SUM(ene) as enero,sum(feb)as febrero, sum(mar) as marzo,sum(abr) as abril, sum(may) as mayo, sum(jun) as junio, sum(jul) as julio, sum(ago) as agosto,sum(sep) as septiembre, sum(oct) as octubre, sum(nov) as noviembre, sum(dic) as diciembre from seisp.incidencia where municipio_id=:munchen and subtipo_id=8  and  anio_id>:year    group by anio_id asc';

        $sqlrat = 'select anio_id, SUM(ene) as enero,sum(feb)as febrero, sum(mar) as marzo,sum(abr) as abril, sum(may) as mayo, sum(jun) as junio, sum(jul) as julio, sum(ago) as agosto,sum(sep) as septiembre, sum(oct) as octubre, sum(nov) as noviembre, sum(dic) as diciembre from seisp.incidencia where municipio_id=:munchen and subtipo_id=9 and  anio_id>:year    group by anio_id asc';

        $sqlrdv = 'select anio_id, SUM(ene) as enero,sum(feb)as febrero, sum(mar) as marzo,sum(abr) as abril, sum(may) as mayo, sum(jun) as junio, sum(jul) as julio, sum(ago) as agosto,sum(sep) as septiembre, sum(oct) as octubre, sum(nov) as noviembre, sum(dic) as diciembre from seisp.incidencia where municipio_id=:munchen and subtipo_id=19 and anio_id>:year    group by anio_id asc';


        $chato = Incidencia:: findBySql($sql, [':munchen' => $val,':year'=>$param,])->all();

        $violacion = Incidencia::findBySql($sqlvio, [':munchen' => $val,':year'=>$param,])->all();

        $hd = Incidencia::findBySql($sqlhd, [':munchen' => $val,':year'=>$param,])->all();

        $narco = \app\models\Narcomenudeo::findBySql($sqlnm, [':munchen' => $val,':year'=>$param,])->all();

        $sec = Incidencia::findBySql($sqlsec, [':munchen' => $val,':year'=>$param,])->all();

        $rch = Incidencia::findBySql($sqlrch, [':munchen' => $val,':year'=>$param,])->all();

        $ran = Incidencia::findBySql($sqlran, [':munchen' => $val,':year'=>$param,])->all();

        $rat = Incidencia::findBySql($sqlrat, [':munchen' => $val,':year'=>$param,])->all();

        $rdv = Incidencia::findBySql($sqlrdv, [':munchen' => $val,':year'=>$param,])->all();

         

         $mun[0]=$this->retDelAI($chato);

         $mun[1]=$this->retDelAI($violacion);

         $mun[2]=$this->retDelAI($hd);

         $mun[3]=$this->retDelAI($narco);

         $mun[4]=$this->retDelAI($sec);

         $mun[5]=$this->retDelAI($rch);

         $mun[6]=$this->retDelAI($ran);

         $mun[7]=$this->retDelAI($rat);

         $mun[8]=$this->retDelAI($rdv);

         unset($chato,$violacion,$hd,$narco,$sec,$rch,$ran,$rat,$rdv);

         return $mun;        

    }

And this is where a call the method


public function actionConsultar($id=null)

    {     

        $model = new Incidencia();

        $mname=null;

        $val=$id; 

        $mname=  \app\models\Municipio::findOne($val);

        $mname=$mname->municipiog;

        $mname=$this->limpiar_caracteres_especiales($mname);

        $mes=date("n")-1;


        $anio=date("Y");

        $idY = Yii::$app->db->createCommand('SELECT id FROM anio where year=:anio')

            ->bindValue(':anio',$anio)

            ->queryOne();

        $munAI=$model->getMunAi($val,$idY['id']);


        

        return $this -> render('graf',['munAI'=>$munAI]);

    }



I hope you can help me to get data as int or how to make my current array into int type. By the way it is a bidimensional array.

Thanks

PHP sometimes messes up types. It depends on the DB driver mainly.

In order to convert string to int use (int) $var. To convert values within an array foreach it.

Thanks I did it.