title: Array to string conversion - Associative Array
body: <p>I use this code below to parse a question and its choices.</p>
  
  <pre><code>$entries = preg_split('/(?=[a-z\d]+\.(?!\d))/', $str, -1, PREG_SPLIT_NO_EMPTY);
  $arrAnswers = array();
  $arrQuestions = array();
  $id = 0; //Assuming your table is empty
  
  foreach($entries as $entry) { //Loop through the grabbed records
    if(is_numeric(substr($entry, 0, 1)) === true) { //Is it a question?
       $id++;     
       $arrAnswers[$id] = array();
       $arrQuestions[$id] = '(\''. $entry .'\')'; 
    } else { //Ok, it's a possible answer to a question
       $arrAnswers[$id][] = '(\''. $entry .'\', '. $id .', 0)';
    }
  }
        echo "&lt;pre&gt;";
          print_r($arrQuestions);
        echo "&lt;pre&gt;";
  
        echo "&lt;br&gt;";
  
        echo "&lt;pre&gt;";
          print_r($arrAnswers);
        echo "&lt;pre&gt;";
  </code></pre>
  
  <p>Which returns these array result:</p>
  
  <pre><code>$arrQuestions output
  
  Array
      (
          [1] =&gt; ('1. What is foo?')
          [2] =&gt; ('2. What is foo?')
      )
  
  $arrAnswers output
      Array
      (
          [1] =&gt; Array
              (
                  [0] =&gt; ('a. foo1', 1, 0)
                  [1] =&gt; ('b. foo2', 1, 0)
                  [2] =&gt; ('c. foo3', 1, 0)
                  [3] =&gt; ('d. foo4', 1, 0)
              )
  
          [2] =&gt; Array
              (
                  [0] =&gt; ('a. foo1', 2, 0)
                  [1] =&gt; ('b. foo2', 2, 0)
                  [2] =&gt; ('c. foo3', 2, 0)
                  [3] =&gt; ('d. foo4', 2, 0)
              )
  
      )
  </code></pre>
  
  <p>My code for the insertion of records:</p>
  
  <pre><code>try {
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  // set the PDO error mode to exception
  $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $strDbQuery = "INSERT INTO `question` (`q_name`) VALUES ". implode(", ", $arrQuestions);
  $strDbQuery_2 = "INSERT INTO `answers` (`choices`, `question`, `correct`) VALUES ". implode(", ", $arrAnswers);
  // use exec() because no results are returned
  $conn-&gt;exec($strDbQuery);
  $conn-&gt;exec($strDbQuery_2);
  echo "New questions uploaded successfully";
  }
  catch(PDOException $e)
  {
  echo $strDbQuery . "&lt;br&gt;" . $e-&gt;getMessage();
  echo $strDbQuery_2 . "&lt;br&gt;" . $e-&gt;getMessage();
  }
  
  $conn = null;
  </code></pre>
  
  <p>I printed the the message of the transaction and on the insertion of the answers, the value being inserted is an array. I used the function <code>implode()</code> but it is still treated as  an array.</p>
  
  <pre><code>INSERT INTO `question` (`q_name`) VALUES ('1. What is foo1?'), ('2. What is foo2?')  
  INSERT INTO `answers` (`choices`, `question`, `correct`) VALUES Array, Array
  </code></pre>
  
  <p>What should I do guys?</p>