PHP if/else statement

前端 未结 6 417
佛祖请我去吃肉
佛祖请我去吃肉 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-21 00:14

    you can try in the following way:

    $body_id = "home";
    
    if ($body_id == "home") {
        echo "I am home!";
    } else {
        echo "I am not home!";
    }
    

    or

    $body_id = "home"; 
    
    if (strcmp($body_id, "home") !== 0) { 
        echo 'I am not home!'; 
    } 
    else { 
        echo 'I am home!'; 
    } 
    

    Reference:

    https://www.geeksforgeeks.org/string-comparison-using-vs-strcmp-in-php/
    

提交回复
热议问题