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.
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!