PHP if/else statement

前端 未结 6 372
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-20 23:29

I\'m a complete newbie to PHP but found it can be very useful. How can I write the following statement in PHP:

If body ID = \"home\" then insert some html, e.g.

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-20 23:54

    You can use a switch command like so:

    switch($body)
    {
        case 'home': //$body == 'home' ?
            echo '

    I am home!

    '; break; case 'not_home': default: echo '

    I'm not home.

    '; break; }

    The default means that if $body does not match any case values, then that will be used, the default is optional.

    Another way is as you say, if/else statements, but if within template / view pages you should try and use like so:

    
        

    I am home!

    I'm not home!

提交回复
热议问题