Theoretically, you can do this.
$variablename = 'IMG' . $i;
echo $$variablename;
or simply
echo ${IMG . $i};
This is a PHP language feature called variable variables.
This is a really bad idea. Do not do it.
Instead, build an array.
$images = array('first', 'second', 'third');
foreach($images as $image) {
echo $image;
}
// or
for ($i = 0; i < count($images); $i++) { // this might be what you already have
echo $images[$i];
}