0

I need a way to declare a variable to use in while loop like this:

$x = 1;
    while ($x < 5){
    echo $row['img$x'];
    $x++;
}

In my case, this returned a syntax error.

Derek Pollard
  • 6,953
  • 6
  • 39
  • 59
Mauricio
  • 9
  • 2

1 Answers1

2

Two options:

$row['img' . $x]
// or
$row["img$x"]

Use double quotes "" if you want to use string interpolation and . for string concatenation.

Jeroen Noten
  • 3,574
  • 1
  • 17
  • 25