Free download web templates, books and more. Free php projects ,games and apps. GTA mods and more

Breaking

php if statement

PHP If Else

PHP if else statement is used to test condition. There are various ways to use if statement in PHP.
  • if
  • if-else
  • if-else-if
  • nested if

PHP If Statement:

PHP if statement is executed if condition is true.otherwise false
Syntax
  1. if(condition){  
  2. //code to be executed  
  3. }  
Flowchart
php if statement flowchart
Example
  1. <?php  
  2. $num=12;  
  3. if($num<100){  
  4. echo "$num is less than 100";  
  5. }  
  6. ?>  
Output:
12 is less than 100

PHP If-else Statement:

the if-else condition is the if part is true to execute the part .
the condition is false to go into else part
PHP if-else statement is executed whether condition is true or false.
Syntax
  1. if(condition){  
  2. //code to be executed if true  
  3. }else{  
  4. //code to be executed if false  
  5. }  
Flowchart
php if-else statement flowchart
Example
  1. <?php  
  2. $num=12;  
  3. if($num%2==0){  
  4. echo "$num is even number";  
  5. }else{  
  6. echo "$num is odd number";  
  7. }  
  8. ?>  
Output:
12 is even number