title: Why do variables inside this for loop return null?
body: <p>I have the following code and it's giving me hell of a time as to why the variables inside the <code>for ($x = 1; $x &lt;= $quantity; $x++)</code> loop are not returning anything but <code>null</code> when called in the database insert query that's following it, or when I try to debug with <code>var_dump($cVnum);</code> for instance.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>if ($cash &gt;= $product['cost'] * $quantity) {
      // Substract cash
      $receiver = $userData['login'];
      if ($receiver != "") {
          //all variables safe
          $database-&gt;setDB("account")-&gt;mkquery("UPDATE {{table}} SET ".$cashfield." = (".$cashfield." - ".$product['cost'] * $quantity.") WHERE id = '".$accountid."' LIMIT 1", "account");
          // For each quantity
          for ($x = 1; $x &lt;= $quantity; $x++) {
              // Insert vnums to item_award
              for ($i = 1; $i &lt;= 4; $i++) {
                  $cVnum = $product['vnum'.$i];
                  if ($cVnum &gt; 0)  {
                      $socket0 = 0;
                      $socket2 = 0;
                      if ($product['vnum'.$i.'_time'] &gt; 0) {
                          if ($cVnum == 72701 || ($cVnum &gt; 71069 &amp;&amp; $cVnum &lt; 71075) || ($cVnum &gt; 72722 &amp;&amp; $cVnum &lt; 72731)) {
                              $socket2 = $product['vnum'.$i.'_time'];
                          } else if ($cVnum == 47001 ||
                              ($cVnum &gt; 41136 &amp;&amp; $cVnum &lt; 41145) ||
                              ($cVnum &gt; 45078 &amp;&amp; $cVnum &lt; 45084) ||
                              ($cVnum &gt; 71164 &amp;&amp; $cVnum &lt; 71168) ||
                              ($cVnum &gt;= 45139 &amp;&amp; $cVnum &lt;= 45144) ||
                              ($cVnum &gt;= 41311 &amp;&amp; $cVnum &lt;= 41314)) {
                                  $socket0 = time() + ($product['vnum'.$i.'_time']*60*60*24);
                          } else {
                              $socket2 = time() + ($product['vnum'.$i.'_time']*60*60*24);
                          }
                      }
                  }
              }
          }                              
          $database-&gt;setDB("player");
          $insert = [
              "login" =&gt; $receiver, 
              "vnum" =&gt; $cVnum, 
              "count" =&gt; $quantity, 
              "given_time" =&gt; array("func", "NOW()"),
              "socket0" =&gt; 22, 
              "mall" =&gt; 1
          ];    
          $logok = $database-&gt;insert($insert, "item_award");
      }
  }
  </code></pre>
  
  <p>I've been at it for like six hours now and can't figure out what's wrong.</p>
  
  <p><strong>UPDATE</strong>: I narrowed down where the problem is with <code>$cVnum = $product['vnum'.$i];</code>. I noticed that when I removed <code>$i</code> and it became <code>$product['vnum']</code> the variable returned the value I expected. Could there be a fix so that I can use with the <code>$i</code> variable though? Why is it returning <code>null</code> when <code>$i</code> variable is included?</p>