SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

PHP IF ELSE statement script and example code

PHP IF statement is popular and is used to check some conditions and accordingly statements are executed. We can control the html display part also by the IF STATEMENT. Here is one simple example of if statement.

$j = 5;
$k = 10;
if ($j < $k){
print "Variable $j value is less  than $k";
}

We can add ELSE condition to the above statement and that part will be executed once the if condition does not satisfy. 


$j = 10;
$k = 5;
if ($j < $k){
print "Variable $j value is less  than $k";  // This line will not be executed
}
else{
print "Variable $j value is greater  than $k"; // This line will be executed
}

If we are checking the different values of a variable which can have more than two conditions then for each case using PHP IF STATEMENT for matching conditions  is not a good idea. In such a case  PHP SWITCH STATEMENT  is to be used.  
One of the important use of PHP IF STATEMENT  is when inside a php script we want to display LOG IN or LOG OUT links.

Discuss this tutorial at forum


 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.