How to Combine an If Statement in PHP
- 1). Open a new file in Notepad by right-clicking the background of your desktop and then selecting "New" followed by "Text File Document."
- 2). Write a single "If" statement at the top of the text file, like this:
if(empty($name))
{
} - 3). Place the logic you would like to run when the "If" statement tests as true. In the above example, the "If" statement checks to see if the "name" variable is empty. If it is empty, you can print something out by writing this within the curly brackets of the "If" statement:
print '<p>Please enter your name.</p>'; - 4). Combine the "If" statement with another "If" statement by using the "elseif" statement. This will only be tested if the first if statement is false. In the example above, this would occur if the name variable is not empty. You can write an "elseif" statement like this in the line directly after the "If" statement:
elseif(empty($idNumber))
{
} - 5). Add some logic to the "elseif" statement. For example, you can write the following line inside the "elseif" statement's curly brackets:
print '<p>Please enter your ID Number.</p>'; - 6). Combine the "if" statement with an "else" statement by writing the following after the "}" curly bracket of the "elseif" statement:
else
{
} - 7). Place some logic into the "else" statement by writing something like this within the curly brackets:
print '<p> Thank you!</p>';