连接语法格式

Ren*_*ibe 0 php concatenation

我有一个php echo语句,用于循环中的复选框:

echo "<input name='battery[$i]' type='checkbox' id='battery[$i]' value='Yes' style='margin-top:10px; margin-left:15px;' />";
Run Code Online (Sandbox Code Playgroud)

我想根据查询结果将此条件添加到它:

<?php if($rowbill['battery'] == "Yes") print "checked"; ?>
Run Code Online (Sandbox Code Playgroud)

但我很难获得连接的正确语法,请一些帮助将不胜感激.

Nic*_*Nic 5

试试这个:

echo "<input name='battery[$i]'" .($rowbill['battery'] == "Yes" ? "checked='checked'" : ""). " type='checkbox' id='battery[$i]' value='Yes' style='margin-top:10px; margin-left:15px;' />";
Run Code Online (Sandbox Code Playgroud)