title: Run PHP function in While Loop
body: <p>I'd like to run a function within a While loop.
  Unfortunately, it works but not quite as desired.</p>
  
  <p>My goal is to read out from a CSV file, each line and is stored in the MySQL database. This also works flawlessly.</p>
  
  <p>In addition, however, I want to let miteinpflegen a value by a numeric random.</p>
  
  <p>Here again my scripts to generate the numerical codes.</p>
  
  <pre><code>function generateCode($length){
  $string = "";
  $numbers = "0123456789";
      for($i=0;$i &lt; $length;$i++) {
          $char = $numbers[mt_rand(0, strlen($numbers)-1)];
          $string .= $char;
      }
  return $string;
  }
  $gencode = generateCode(8);
  </code></pre>
  
  <p>Works great.</p>
  
  <p>And here my while loop ($handle is in my case the var to open CSV file)</p>
  
  <pre><code>while (($data = fgetcsv($handle, 10000, ";")) !== FALSE) {
      $import = "INSERT into jobs(id,link_id,random number) values('NULL','$linkid','$gencode')";
      mysql_query($import) or die(mysql_error());
  }
  </code></pre>
  
  <p>But how do I get it back now that each line of the CSV file gets its own random number or rather, which is calculated in each row $gencode new?
  At the moment i get one random number for all rows.</p>
  
  <p>For help, I am very grateful.
  I just can no longer see the forest for the trees.</p>
  
  <p>Thank you</p>