I am using code igniter.
I have quite a large list of items being sent through post, some will be set, some wont be.
I have two ways of approaching the same problem.
/*DYNAMIC CODING */
$fields = array(
'field1', 'field2',
'field3', 'field4',
'field5', 'field6',
'fiel'... ...);
foreach($fields as $f)
$$f = $this->input->post($f);
/* OR LITERAL CODING? */
$field1 = $this->input->post('field1');
$field2 = $this->input->post('field2');
$field3 = $this->input->post('field3');
$field4 = $this->input->post('field4');
$field5 = $this->input->post('field5');
$field6 = $this->input->post('field6');
$field7 = $this->...
Both methods will work, my question is, is there any reason to use one over the other?
Use dynamic coding in my experience, because it is my personal preference.
If your preference is either or the other, then use whatever you feel comfortable with, if you are coding with a means of someone else editing the code, whatever you choose make sure you add;
// a comment
to explain your code. Using either will differ in process time by a minimal unnoticeable amount of milliseconds, but understanding your code and commenting it correctly will save you alot more than milliseconds in the long run!