-2

I have this php script:

<?php
$tmp = $_POST['N1']; 
$tmp = $_POST['N2'];
$tmp = $_POST['N3']; 
$tmp = $_POST['N4']; 
?>

I want to use a for loop instead:

<?php

for ($i = 0; $i < 4; $i++) { 
$tmp = $_POST['N$i']; 
}
?>

How come this doesn't work?

drudge
  • 35,471
  • 7
  • 34
  • 45
verlager
  • 794
  • 5
  • 25
  • 43

1 Answers1

0

in php strings in ' are parsed as plain text not a variable

use your syntax like this:

<?php

for ($i = 0; $i < 4; $i++) { 
$tmp = $_POST["N$i"]; 
}
?>

for a better code structure use foreach in this case...

roozgar
  • 412
  • 1
  • 5
  • 19
peiman F.
  • 1,648
  • 1
  • 19
  • 42