Adscend

If Statement Syntax Example


If Statement


Syntax:
if(condition)
{
     // execute this block if condition is true
}


Conditional statements are used to perform different actions based on different conditions.
1.If statements is also known as conditional statements. This simply means that they are able to take action based on various conditions.
2.If statements is used to check whether specified condition is true or false.
3.If statements allows the computer to make decisions based on the values of variables which can take the specified action based on the input that is given.

Example: 1

<?php 
$num1
=20$num2=30
if (
$num1<$num2
  echo 
"This line will show on browser"?>
Output
This line will show on browser

Example: 2

<?php 
$num1
=20$num2=30
if (
$num2<$num1
  echo 
"This line will not show on browser"?>
Output
The browser will show nothing
Because, the condition is false and 30 is greater than 20.


No comments:

Post a Comment