title: store array values in a separate row
body: <p>Here, I’m inserting the dynamic array values into database table. It’s inserting the data into database table perfectly. But, I need a little bit modification with this code. It’s inserting the data with <code>,</code>. But, I want to store the array values in a separate row.</p>
  
  <p>Now I have:</p>
  
  <pre><code>  id  field_name
  
     1   aaa, bbb, ccc, ddd
  </code></pre>
  
  <p>But I need:</p>
  
  <pre><code>   id  field_name
  
     1   aaa
     2   bbb
     3   ccc
     4   ddd
  </code></pre>
  
  <p>How can I achieve that?</p>
  
  <pre><code>$choose_general_rules = $_POST['choose_general_rules'];
  $choose_no_of_questions = $_POST['choose_no_of_questions'];
  $choose_mark_questions = $_POST['choose_mark_questions'];
  
  $choose_question_name = $_POST['choose_question_name'];
  $question = array();
  foreach($choose_question_name as $value) {
   $question[] = $value;
  }
  $result_question = implode(',', $question);
  
  $answer_1 = $_POST['answer_1'];
  $answer_one = array();
  foreach($answer_1 as $value) {
   $answer_one[] = $value;
  }
  $result_answer_one = implode(',', $answer_one);
  
  $answer_2 = $_POST['answer_2'];
  $answer_two = array();
  foreach($answer_2 as $value) {
   $answer_two[] = $value;
  }
  $result_answer_two = implode(',', $answer_two);
  
  $answer_3 = $_POST['answer_3'];
  $answer_three = array();
  foreach($answer_3 as $value) {
   $answer_three[] = $value;
  }
  $result_answer_three = implode(',', $answer_three);
  
  $answer_4 = $_POST['answer_4'];
  $answer_three = array();
  foreach($answer_3 as $value) {
   $answer_three[] = $value;
  }
  $result_answer_three = implode(',', $answer_three);
  
  try
  {
      $stmt = $dbh-&gt;prepare("INSERT INTO choose_the_correct_answer ( reference_id, general_rules, no_of_questions, mark_each_questions, question, answer_option_one, answer_option_two, answer_option_three, answer_option_four ) VALUES ( :ref_id, :choose_general_rules, :choose_no_of_questions, :choose_mark_questions, :choose_question_name, :answer_1, :answer_2, :answer_3, :answer_4 )");
      $stmt-&gt;bindParam(':ref_id', $lastid, PDO::PARAM_INT);
      $stmt-&gt;bindParam(':choose_general_rules', $choose_general_rules, PDO::PARAM_STR);
      $stmt-&gt;bindParam(':choose_no_of_questions', $choose_no_of_questions, PDO::PARAM_STR);
      $stmt-&gt;bindParam(':choose_mark_questions', $choose_mark_questions, PDO::PARAM_STR);
      $stmt-&gt;bindParam(':choose_question_name', $result_question, PDO::PARAM_STR);
      $stmt-&gt;bindParam(':answer_1', $result_answer_one, PDO::PARAM_STR);
      $stmt-&gt;bindParam(':answer_2', $result_answer_two, PDO::PARAM_STR);
      $stmt-&gt;bindParam(':answer_3', $result_answer_three, PDO::PARAM_STR);
      $stmt-&gt;bindParam(':answer_4', $result_answer_three, PDO::PARAM_STR);
      $stmt-&gt;execute();
  }
  catch(PDOException $e)
  {
      echo "Error Inserting datas into database :" .$e-&gt;getMessage();
  }
  </code></pre>