title: Pass variable from loop to function
body: <p>I've been working with Php for less than 2 months (this is also my first question so please tell me if I'm missing something) and it has been going smooth right up till today. I'm working on a form plugin for Wordpress and currently implementing the code to make the forms saved in the database to connect with a shortcode which includes the ID of the form in the database. The 1st form has an ID of 1 and the shortcode is IForm_1. Pretty simple.</p>
  
  <p>The problem occurs when looping thru all the forms and not being able to pass the $ID value from the loop to the IForm function.</p>
  
  <pre><code> $ID= 0;
   $FormID= 0;
   settype($ID, "integer");
  
     for ($x = 1; $x &lt;= 300; $x++) {
          global $ID;
          $ID++;
          $ShortCode = "IForm_";
          $ShortCode .= $ID;
          $FormID = $ID;
         add_shortcode( $ShortCode, 'IForm_Array' );
          $ShortCode ='';
  }
  </code></pre>
  
  <p>here is the loop which is very simple, when the $ShortCode lines up with the shortcode used on the site it works and the IForm get used as it should. </p>
  
  <pre><code>function IForm(){
      global $ID;
      //testing_decode();
      // Gets the value of baseTest from getDB and puts it in test.
      $DBForm = getDB($ID);
      $Form = $DBForm;
      $Form .=  "Works but not really";
      return $Form;
  
  }
  </code></pre>
  
  <p>Here is the function. </p>
  
  <p>Problem is that $ID is always 300 in the function which is the end of the loop. IForm is executed when the $ID in the loop lines up with the shortcode ID on the site/post which tells me the $ID value is indeed correct for some part of the loop. When the ID is indeed correct I would like to pass it to the IForm function to use it to find the right form in the database(MySQL). </p>
  
  <p>Now my question is how would I pass (if that can even be done) the $ID value on the 3rd row of the loop to the 5th row of function. Alternatively would be to force break the loop when it lines up and use the last $ID value to be passed to IForm.</p>