CodeIgniter Forums
Use foreach for input->post() ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Use foreach for input->post() ? (/showthread.php?tid=47860)



Use foreach for input->post() ? - El Forum - 12-25-2011

[eluser]snoo[/eluser]
Hi guys,

I have a form that has couple of input fields that may or may not be available depending on user input. Normally I use

Code:
foreach($_POST as $k=>$v){

}

Is this a recommended practice in CI?

Can I use
Code:
foreach($this->input->post() as $key=>$value)
{
if($key != 'submit'){
  $data[$key] = $value;
}
}

$insert = $this->db->insert('database', $data);

thanks!