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.
Post Comment This is for short comments only. Use the forum for more discussions.
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer