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,630
  • 6
  • 37
  • 54
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,514
  • 1
  • 16
  • 25