title: How to add send array in the SQL query and calculate SUM using PHP
body: <p>I have an array in variable <code>$id = Array([0] =&gt; 5 , [1]=&gt; 6)</code>. Now I want to pass the value to the SQL query and calculate the SUM, but somehow it's not calculating the SUM rather then its displaying output 100500 which should be 600 (like: 100+500 = 600).</p>
  
  <p>My PHP code is :</p>
  
  <pre><code>$id = $_POST['id'];
  for($i = 0; $i&lt;count($id); $i++) {
  $sql = getAmount($id[$i]);
  }
  
  function getAmount(&amp;$id){
  global $mysqli;
  $stmt = $mysqli-&gt;prepare("SELECT SUM(amount) AS total FROM work WHERE id = (?)");
  $stmt-&gt;bind_param("s",$id);
  $stmt-&gt;execute();
  $stmt-&gt;bind_result($amount);
      $stmt-&gt;fetch();
  echo $amount['total'];
   }
  </code></pre>