SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

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.

Further readings
Loops and program structure of PHP scripts
Checking variables by isset
switch
For Loop
if else condition checking
while loop
Do while loop
PHP beginners guide


Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
PHP Tutorials
Basic Loops
PHP Monthly Planner
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.