PHP的方括号:什么时候引用引号而什么时候不引用?
发布时间:2020-12-13 16:47:14 所属栏目:PHP教程 来源:网络整理
导读:htmlheadtitle/title/headbody?phpif (isset ($_POST['posted'])) {if ($_POST['question1'] == "Lisbon") { echo "You are correct,$_POST[question1] is the right answerhr";}if ($_POST['question1'] != "Lisbon") { echo "You are incorrect,$_POST[que
<html> <head><title></title></head> <body> <?php if (isset ($_POST['posted'])) { if ($_POST['question1'] == "Lisbon") { echo "You are correct,$_POST[question1] is the right answer<hr>"; } if ($_POST['question1'] != "Lisbon") { echo "You are incorrect,$_POST[question1] is not. the right answer<hr>"; } } ?> <form method="POST" action="quiz.php"> <input type="hidden" name="posted" value="true"> What is the capital of Portugal? <br> <br> <input name=''question1" type=''radio" value=''Porto''> Porto <br> <input name=''question1" type="radio" value=''Lisbon''> Lisbon <br> <input name="question1" type="radio" value=''Madrid''> Madrid <br> <br> <input type=''submit''> </form> </body> </html> 这是整个部分,它来自PDF.但事实上,他们没有说明为什么他们在if语句中使用”作为question1但在echo语句中没有使用引号. 简而言之:为什么$_POST [‘question1’]在if语句中有” 解决方法
始终使用引号(对于字符串键),除非在双引号字符串中.请参见手册的
the string parsing section.
$juices = array("apple","orange","koolaid1" => "purple"); echo "He drank some $juices[0] juice.".PHP_EOL; echo "He drank some $juices[1] juice.".PHP_EOL; echo "He drank some juice made of $juice[0]s.".PHP_EOL; // Won't work echo "He drank some $juices[koolaid1] juice.".PHP_EOL; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |