解析错误:语法错误,意外T_FOR

use*_*412 -1 html php

我正在尝试创建一个带有下拉列表的html表单.以下是我的代码:

$output[]='<td><select name="qty'.$name.'">'
 for($count=1;$count<=$total;$count+=1) {
     '<option value="'.$count.'">'.$count.'</option>'
}
'</select>
 </td>';
Run Code Online (Sandbox Code Playgroud)

谁能告诉我可能是什么问题?另外如何将默认选择值设置为1?

Rap*_*tor 7

你错过了分号:

$tmp ='<td><select name="qty'.$name.'">';
for($count=1; $count <= $total; $count+=1) {
     $tmp .= '<option value="'.$count.'"';
     if($count == 1) {
       $tmp .= ' selected="selected"';
     }
     $tmp .= '>'.$count.'</option>';
}
$tmp .= '</select></td>';
$output[] = $tmp;
Run Code Online (Sandbox Code Playgroud)

更新:添加"将默认值设置为1"