Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中的“echo”中添加for循环_Php_Loops - Fatal编程技术网

在PHP中的“echo”中添加for循环

在PHP中的“echo”中添加for循环,php,loops,Php,Loops,在PHP echo中是否可能在其内部包含for循环? 大概是这样的: echo "This are the list" . for($i=0; $i<=$count; $i++) { echo $variable1 . $variable2} . "End"; 我的代码是这样的 但我仍然会遇到错误。循环不会进入echo语句内部。把他们分开 echo "This are the list"; for($i=0; $i<=$count; $i++) { echo $variable1

在PHP echo中是否可能在其内部包含for循环? 大概是这样的:

echo "This are the list" . for($i=0; $i<=$count; $i++) { echo $variable1 . $variable2} . "End";
我的代码是这样的


但我仍然会遇到错误。

循环不会进入echo语句内部。把他们分开

echo "This are the list";
for($i=0; $i<=$count; $i++)
{
 echo $variable1 . $variable2;
} 
echo "End";
可通过以下方式生成更可读的输出版本:

echo "This is the list: <br>";
for($i=0; $i<=$count; $i++)
{
 echo $variable1. " ". $variable2."<br>";
} 
echo "End";
否;它不能像函数或方法那样充当代码块。但你当然可以做到这一点:

echo "This are the list";
for ($i=0; $i<=$count; $i++) {
    echo $variable1 . $variable2;
}
echo "End";
不,您不能这样做您不能在echo语句中循环,您可以这样做:

$text = 'This are the list ';

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

$text .= 'End';

echo $text;

不,不会那样的

你有两个选择

选择1 选择2
…您收到的错误是什么?它可能会帮助其他人。准确地说,你想要什么。结果会是什么。你不需要投入。for循环前后否否,您不能将控制结构与其简单的答案连接起来,我不认为关键字for ACCEPTES运算符。或者是否可以将for循环的结果存储在变量中???高科技,非常感谢。。选择1解决了我的头痛。我欠你一杯咖啡D
$temp_string = '';
for ($i=0; $i<=$count; $i++)
{
 $temp_string .= $variable1 . $variable2;
}
echo "This are the list".$temp_string;
echo "This are the list";
for($i=0; $i<=$count; $i++)
{
 echo $variable1 . $variable2;
} 
echo "End";