本文介绍了如何在回声中嵌入if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对此感到头疼。我需要把if语句放在echo中(这个echo是在一个函数中,它是用于一个表单实际提交的)。下面是我的部分代码示例。在这种情况下,我怎么能把这些if语句放入我的echo中?
<?php echo'< td> < select id =depuisname =depuis>
< option value = \'4 \\''<?php if(isset($ _ POST [\'depuis \''))&& $ _POST [\'depuis \' ] == \'4 \\''){echo \'selected \\'; } else {echo''; }?> >< /选项>
< option value = \'1 \'<?php if(isset($ _ POST [\'depuis \''))&&& $ _POST [\'depuis \' ] == \''''){echo \\''selected''; } else {echo''; }?> > 2 ans et moins< / option>
< option value = \'2 \\''<?php if(isset($ _ POST [\'depuis \''))&& $ _POST [\'depuis \' ] == \'2''){echo \\''selected';'; } else {echo''; }?> > 2& agrave; 5 ans< / option>
< option value = \'3 \\''<?php if(isset($ _ POST [\'depuis \''))&&& $ _POST [\'depuis \' ] == \'3''){echo \\''selected''; } else {echo''; }?> > 5 ans et plus< / option>
< / select>
< / td>'
; ?>
解决方案
一切都是php,所以需要使用更多的第一<?php
在检查之前完成每个
。像这样: echo
if
<?php
echo'< td>< select id =depuisname = depuis >
< option value =4';
if(isset($ _ POST ['depuis'])&& $ _POST ['depuis'] =='4'){
echo'selected';
}
echo'>这里有些东西可能?< / option> ...等
I'm gettin' a headache on that. I need to put if statement inside an echo (this echo is in a function, it's for a form submit actually)
Here is an example on a partial of my code. In this situation, how can I put theses if statement inside my echo??
<?php echo '<td><select id="depuis" name="depuis">
<option value=\'4\' <?php if(isset($_POST[\'depuis\']) && $_POST[\'depuis\'] == \'4\'){ echo \'selected\'; } else { echo ''; } ?> ></option>
<option value=\'1\' <?php if(isset($_POST[\'depuis\']) && $_POST[\'depuis\'] == \'1\'){ echo \'selected\'; } else { echo ''; } ?> >2 ans et moins</option>
<option value=\'2\' <?php if(isset($_POST[\'depuis\']) && $_POST[\'depuis\'] == \'2\'){ echo \'selected\'; } else { echo ''; } ?> >2 à 5 ans</option>
<option value=\'3\' <?php if(isset($_POST[\'depuis\']) && $_POST[\'depuis\'] == \'3\'){ echo \'selected\'; } else { echo ''; } ?> >5 ans et plus</option>
</select>
</td>'
; ?>
解决方案
Everything is php so need to use more than the first <?php
Finish each echo
before checking with if
. Like this:
<?php
echo '<td><select id="depuis" name="depuis">
<option value="4"';
if(isset($_POST['depuis']) && $_POST['depuis'] == '4') {
echo ' selected';
}
echo ' >Something here maybe?</option>...etc
这篇关于如何在回声中嵌入if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!