在PHP中的'echo'中添加for循环

Is it possible in PHP echo to have for loop inside of it? Something like this:

echo "This are the list" . for($i=0; $i<=$count; $i++) { echo $variable1 . $variable2} . "End";

My code goes like this.

but I still experience error.

Nope it's not going to work like that.

You have two options.

Option 1

$temp_string = '';
for ($i=0; $i<=$count; $i++)
{
 $temp_string .= $variable1 . $variable2;
}
echo "This are the list".$temp_string;

Option 2

echo "This are the list";
for($i=0; $i<=$count; $i++)
{
 echo $variable1 . $variable2;
} 
echo "End";

Loops dont go inside an echo statement. Separate them

echo "This are the list";
for($i=0; $i<=$count; $i++)
{
 echo $variable1 . $variable2;
} 
echo "End";

A more readable version of the output would be generated by:

echo "This is the list: <br>";
for($i=0; $i<=$count; $i++)
{
 echo $variable1. " ". $variable2."<br>";
} 
echo "End";

No. echo only accepts strings; it cannot serve as a code block like a function or method. But you can certainly do this:

echo "This are the list";
for ($i=0; $i<=$count; $i++) {
    echo $variable1 . $variable2;
}
echo "End";

No you cannot do like that you cannot loop in echo statement, you can do like this :

$text = 'This are the list ';

for($i=0; $i<=$count; $i++){
    $text .=  $variable1.$variable2;
}

$text .= 'End';

echo $text;