store information in a foreach cycle

0

I have a foreach cycle to go through all the states and I need that all the states are stored in the variable but only the last state is being stored, how can I do so that it does not substitute the value for each iteration? here the controller code

 foreach ($estados as $estado) {
        $datos['codigo_estado'] = $estado['codigo_estado'];
        $porEstados =  $this->modelo_base_m->cuentaPorEstados($datos);
    }

and here the code of the model

   public function cuentaPorEstados($datos){
  extract($datos);
  $cadena = "(fecha_registro >= '$fecha_inicio' AND fecha_registro <= '$fecha_fin') AND (edad >=0 AND edad <=120)";
  $this->db->select('*');
  $this->db->from('dean_eapg.v_evaluaciones');
  $this->db->where($cadena);
  $this->db->where('codigo_estado',$codigo_estado);

  $rs = $this->db->get();
  $resultado = $rs->result_array();
  return $resultado;
}
    
asked by Angel Gutierrez 18.12.2017 в 16:42
source

1 answer

4

It stores the last status because every time you enter the cycle the value previously saved by the new value is being replaced, if you want to store all the states you should use an array:

foreach ($estados as $estado) {
    $datos['codigo_estado'] = $estado['codigo_estado'];
    $porEstados[] = $this->modelo_base_m->cuentaPorEstados($datos);
}
    
answered by 18.12.2017 в 16:49