title: How to insert an array into database
body: <pre><code>$rate=[10,20,40,50,70];
  </code></pre>
  
  <p>How do I insert the value in below query?</p>
  
  <pre><code>$sql="INSERT INTO rental(day_1,day_3,day_7,day_15,day_30)
        VALUES('{$rate[0]}','{$rate[1]}', '{$rate[2]}','{$rate[3]}','{$rate[4]}')";
  
  $stmt =connection::$pdo-&gt;prepare($sql);
  $stmt-&gt;execute();
  </code></pre>
  
  <p>I tried below but it inserts same value in all column for a record and creates new record for each new value:</p>
  
  <pre><code>foreach($rate as $key-&gt;$value)
  {  
      $sql="INSERT INTO rental(day_1,day_3,day_7,day_15,day_30)
            VALUES('{$value}','{$value}', '{$value}','{$value}','{$value}')";
  
      $stmt =connection::$pdo-&gt;prepare($sql);
      $stmt-&gt;execute();
  </code></pre>
  
  <p>Edited based on answer given</p>
  
  <pre><code>public function rentalRate()
      {
  
  $rate = implode("','",$this-&gt;rate);
  $sql = "INSERT INTO rental(day_1,day_3,day_7,day_15,day_30)VALUES('$rate')";
  $stmt =connection::$pdo-&gt;prepare($sql);
          $stmt-&gt;execute();
          unset($rate);
      }
  </code></pre>