title: how to send data to mysqli with an index number (prepared statement)
body: <p>I am creating an array from dynamic created input fields and then send the array over to php, in php I create a foreach loop and try to insert it into my database.</p>
  
  <p>I have created a foreach loop for my array and insert the values like that in my database, however my problem is: You cannot bind a variable with an index number to your query string. I have already verified whether it's actually an array what I am sending and the answer is: Yes. it is an array.</p>
  
  <pre><code>$stmt = $conn-&gt;prepare('INSERT INTO vv(event_id, vvType, vvCosting) VALUES (?, ?, ?)');
  foreach ($example as $index =&gt; $value) {
      $stmt-&gt;bind_param('iss', $id, $example, $example_costs);
  
      $id = $id;
      $example = $value;
      $example_costs = example_costs[$index]; //this DOES NOT work
      $stmt-&gt;execute();
  }
  </code></pre>
  
  <p>So what I want would be the following: Create one foreach loop for my <code>$example</code> variable and based on the index numbers it has also insert the data from the variable <code>example_costs</code> and insert that in the database as well. You shouldn't worry about whether the index value exists or not in my <code>example_costs</code> variable, since they're "pairs".</p>
  
  <p>I know the problem is that I cannot bind my variable like this:</p>
  
  <pre><code>$example_costs[$index]
  </code></pre>
  
  <p>So now my question is: How can I bind my variable like the above? But in a way php DOES accept? Or do I need to create 2 foreach loops? --> Something I would rather NOT do.</p>