取消注释 echo 中的 php/html 语句

uncomment php/html statements within echo

我刚开始学习 php 中的一些 tuts 和代码,并且在 echo 中取消注释 php 代码时遇到问题。我希望你能帮助我。

这是我无法处理的表单片段..

echo '   <div class="form-group">';
echo '      <label class="col-md-3 col-xs-12 control-label" for="textinput">vehicle <span class="required">*</span></label>';
echo '      <div class="col-md-6 col-xs-12">';
echo '         <label class="radio-inline">';
echo '            <input type="radio" name="type" id="radio3" value="car"' . if (isset($_GET['id'])) {echo $row->type == "car" ? 'checked="checked"' : "";}.'> car <span class="required">*</span>';
echo '         </label>';
echo '         <label class="radio-inline">';
echo '            <input type="radio" name="type" id="radio4" value="plane"' .if (isset($_GET['id'])) {echo $row->type == "plane" ? 'checked="checked"' : "";}.'> plane <span class="required">*</span>';
echo '         </label>';
echo '      </div>';
echo '   </div>';

我知道,if 子句不正确。应该是这样吧?

echo (isset($_GET['id'])) ? 'car' : 'not car');

但是我不知道如何用这个例子转换我的 isset ._.

感谢您的帮助!

这就是您要查找的内容:

echo '  <input type="radio" name="type" id="radio3" value="car"' . (isset($_GET['id']))?($row->type == "car" ? 'checked="checked"' : "") : "" .'> car <span class="required">*</span>';
echo '  <input type="radio" name="type" id="radio4" value="plane"' .(isset($_GET['id']))?($row->type == "plane" ? 'checked="checked"' : "") : "".'> plane <span class="required">*</span>';

为了让你的代码更具可读性,你应该这样做:

<?php
?>
<div class="form-group">
    <label class="col-md-3 col-xs-12 control-label" for="textinput">vehicle <span class="required">*</span></label>
    <div class="col-md-6 col-xs-12">
        <label class="radio-inline">
            <input type="radio" name="type" id="radio3" value="car" <?php echo (isset($_GET['id']))?($row->type == "car" ? 'checked="checked"' : "") : "" ?> > car <span class="required">*</span>
        </label>
        <label class="radio-inline">
            <input type="radio" name="type" id="radio4" value="plane" <?php echo (isset($_GET['id']))?($row->type == "plane" ? 'checked="checked"' : "") : "" ?> > plane <span class="required">*</span>
        </label>
    </div>
</div>