Q: Generate array with for loop I am using CodeIgniter framework and getting values from html form.
Currently i am preparing array with fixed number of inputs, ques_X are inputs, But when ques_x numbers are increasing, i need to manually add each key pair value, like ques_11, ques_12...
$answers = array(
                'ques_1'    =>  $this->input->post('ques_1', TRUE),
                'ques_2'    =>  $this->input->post('ques_2', TRUE),
                'ques_3'    =>  $this->input->post('ques_3', TRUE),
                'ques_4'    =>  $this->input->post('ques_4', TRUE),
                'ques_5'    =>  $this->input->post('ques_5', TRUE),
                'ques_6'    =>  $this->input->post('ques_6', TRUE),
                'ques_7'    =>  $this->input->post('ques_7', TRUE),
                'ques_8'    =>  $this->input->post('ques_8', TRUE),
                'ques_9'    =>  $this->input->post('ques_9', TRUE),
                'ques_10'   =>  $this->input->post('ques_10', TRUE))

Is it possible to create something with for or foreach loops?

A: You can create a for loop like this:
$answers = array();
for($i = 1; $i <= 10; ++$i){
    $answers['ques_'.$i] = $this->input->post('ques_'.$i, TRUE);
}


A: Use an array instead of ques_n naming for the inputs.
<input type="text" name="questions[]" value="value1"/>
<input type="text" name="questions[]" value="value2"/>
<input type="text" name="questions[]" value="value3"/>

and then you can just get the data like this:
$answers = $this->input->post('questions', TRUE);
Edit based on the comment of  rjcod:
You can also generate the inputs like this, and still use the same php code:
<input type="text" name="questions[0]" value="value1"/>
<input type="text" name="questions[1]" value="value2"/>
<input type="text" name="questions[2]" value="value3"/>
<!-- This 3 radio buttons are grouped, you can also wrap them in
fieldset if you want -->
<input type="radio" name="questions[3]" value="1"/>
<input type="radio" name="questions[3]" value="2"/>
<input type="radio" name="questions[3]" value="3"/>


A: Your can try this: 
 $data = array();
 $post_length = sizeof($_POST);

   for($i = 1; $i <= $post_length; ++$i){
        $data ['ques_'.$i] = $this->input->post('ques_'.$i, TRUE);
    }

Or you can use this which is fully dynamic.
$data = array();
foreach($_POST as $key=>$value)
    {
      $data [$key] = $this->input->post($key, TRUE);
      //or 
      //$data [$key] = $value;
    }

