使用PHP的If/Else语句

If/Else statement using PHP?

本文关键字:Else 语句 If PHP 使用      更新时间:2023-09-26

我正在尝试做一项调查,根据人们的回答,我想返回一个答案。我使用PHP来使用If/Else语句,而且我对PHP非常陌生。由于PHP与带有If/Else语句的Javascript非常相似,除了$符号之外,我曾尝试在其中添加getelement.byid()函数,但似乎遇到了语法错误,无法弄清楚这是什么

<?php
function order()
{
if $doc->getElementById(ball) then 
    {print "you chose ball";
    }

}
?>

我得到的错误是在中,如果$doc->getElementById(ball),那么行。这是一个从HTML页面调用的PHP页面。我确信这是小问题,但有人知道这句话漏了什么/错了吗?

这只是基本语法。条件周围没有括号:

if (condition){
    //do something
}
if ($doc->getElementById(ball)){
    print "you chose ball";
}

以下是关于if语句

的文档
<?php
function order()
{
    if ($doc->getElementById(ball))
    {
        print "you chose ball";
    }
}
?>

您的代码有几个错误,我将在注释中列出:

<?php
function order()
{
    // Missing opening/closing parentheses (); no "then" in php.
    if ($doc->getElementById(ball))
    // Where are you referencing $doc from? Unlike javascript, php does not have built-in DOM manipulation.    
    {print "you chose ball";
    }

}
?>