if (condition) {
//write a code to be executed
}
<!DOCTYPE html> <html> <body> <?php $a=24; $b=50; if ($a < $b) { echo "a is less than b"; } ?> </body> </html>
if (condition) {
//write a code to be executed
}else {
//write a code to be executed
}
<!DOCTYPE html> <html> <body> <?php $age = 20; if ($age > "18") { echo "you are eligible for voting"; } else { echo "you not are eligible for voting"; } ?> </body> </html>
if (condition) {
//code to be executed if condition 1 is true
} elseif (condition) {
//code to be executed if condition 2 is true
} else {
//code to be executed if all given conditions are false
}
<!DOCTYPE html> <html> <body> <?php $no = 10; if ($no > "0") { echo "Positive number"; } else if($no == "0"){ echo "Number is zero"; } else { echo "Negative number"; } ?> </body> </html>
if (condition)
{
if (condition) {
//write a code to be executed
}
else {
//write a code to be executed
}
}
<!DOCTYPE html> <html> <body> <?php $age = 20; $nationality = "Indian"; if ($nationality == "Indian") { if ($age > "18") { echo "you are eligible for voting"; } else { echo "you are not eligible for voting"; } } else{ echo "Nationality is not indian"; } ?> </body> </html>