Conditional Statements

In PHP, conditional statements work much like they would in Java. you have an "if" statement, "else if" and "else". Interestingly enough, the "else if" statement can be typed as "elseif" and it will still work. An "if" statement will give a condition and, if it is met, the code within that conditional statement will execute. The "else if" statement will give another specific condition to check if the "if" statement's condition has been met and will execute the code contained within it if its condition is met. The "else" statement will handle all other cases. Below is an example of code for a basic conditional statement. Conditional statements in PHP can also be used in an HTML framework as I will demonstrate later on when they are used in loops and for some other functions. The PHP code must just be put in PHP tags within the HTML.

<?php
$value = 11;
if($value==10){
 echo 'the condition has been met!';
}else if($value>10){
 echo 'value too high';
}else{
 echo 'the condition has not been met';
}
?>

Comments

Popular posts from this blog