We can also incorporate more complex PHP within our scripts.
<?php $lucky_number = 5 * 2 - 1; echo "<h1>Your lucky number is ${lucky_number}</h1>"; ?>
The code above will be translated into HTML with a header that reads: Your lucky number is 9
.
We can incorporate all the language features we know about PHP, including functions:
<?php function makeHeaderGreeting ($name){ return "<h1>Hello, ${name}!</h1>"; } echo makeHeaderGreeting("World"); ?>
The code above will be translated into HTML with a header that reads: Hello, World!
.
Instructions
At the top of index.php, we’ve added some PHP variables and functions.
In these checkpoints, you’ll be adding code within the PHP block under the h2
tag.
This section will contain information about the data stored in $about_me
.
First things first - let’s introduce the person. Access the 'name'
from the $about_me
array within your introduction. Place this greeting in an h3
tag.
You can pass a person’s data array (like $about_me
) into the calculateAge
function to determine someone’s age.
Add a paragraph tag under the h3
and state how old this person is. Be sure to use calculateAge
. You may have to use PHP’s concatenation operator.
Add a final div
and use it to tell us the person’s favorite food.