PHP Conditional Statements : If Else If Statements : 7th Day Lecture of PHP



PHP Conditional Statements : If Else If Statements

What is PHP Conditional Statements?

when you write code, you want to perform different actions for different decisions.
You can use conditional statements in your code to do this
  1. If : executes some code only if a specified condition is true
  2. if...else statement - executes some code if a condition is true and another code if the condition is false
  3. if...elseif....else statement - selects one of several blocks of code to be executed

If Example

if...else Example

Have a good night!

if...elseif....else else Example

Have a good night!

 <html>  
   <head>  
     <title><?php $pagetitle="PHP Conditional Statements : If Else If Statements";  
                               define("blogname","Samee Articles");  
                          echo $pagetitle . ":" . blogname ?></title>  
         <meta name="description" content="<?php echo $pagetitle ?>" />  
         <meta name="robots" value="nofollow, noindex" />  
     <link rel="icon" type="image/ico" href="http://www.iconarchive.com/download/i50954/deleket/3d-cartoon-vol3/Web-Coding.ico" alt="Icon" />  
     <link type="text/css" href="stylesheet.css" rel="stylesheet" />  
   </head>  
   <body>  
        <div id="main">  
       <img id="logo" src="http://icons.iconarchive.com/icons/deleket/3d-cartoon-vol3/256/Web-Coding-icon.png" alt="Coding">  
       <h1 align="center"><?php echo $pagetitle ?></h1>  
          <h2 align="left">What is PHP Conditional Statements?</h2>  
           <?php  
             echo "when you write code, you want to perform different actions for different decisions.<br>  
                               You can use conditional statements in your code to do this";  
                               echo "<ol type=\"A\">  
                                         <li>If : executes some code only if a specified condition is true</li>  
                                         <li>if...else statement - executes some code if a condition is true and another code if the condition is false</li>  
                                         <li>if...elseif....else statement - selects one of several blocks of code to be executed</li>  
                                         </ol>";  
           ?>   
          <h2 align="left">If Example</h2>  
           <?php  
                               $t=date("H");  
                               if ($t<"20")  
                                {  
                                echo "Have a good day!";  
                                }  
           ?>   
          <h2 align="left">if...else Example</h2>  
           <?php  
                               $t=date("H");  
                               if ($t<"20")  
                                {  
                                echo "Have a good day!";  
                                }  
                               else  
                                {  
                                echo "Have a good night!";  
                                }  
                          ?>  
         <h2 align="left">if...elseif....else else Example</h2>  
           <?php  
                               $t=date("H");  
                               if ($t<"10")  
                                {  
                                echo "Have a good morning!";  
                                }  
                               elseif ($t<"20")  
                                {  
                                echo "Have a good day!";  
                                }  
                               else  
                                {  
                                echo "Have a good night!";  
                                }  
                          ?>  
     <div id="sidebar">  
       <ul>  
            <li><?php echo "<a href=\"http://sameearticles.blogspot.com\">blogname</a>"?></li>  
         <li><a href="http://www.blogger.com/home">Blogger</a></li>  
         <li><a href="http://sameearticles.blogspot.com/search/label/PHP%20Learning">PHP Learning</a></li>  
         <li><a href="http://seoacquire.blogspot.com">SEO Knowledge</a></li>  
         <li>CSS Learning</li>  
       </ul>  
           </div>    
   </body>  
 </html>  


Post a Comment

Give your reviews about this blog. Leave your comments. What do you think about this post?

Comments Guidelines:

1) I love to read comments, but please avoid spam.

2) Like this blog, share your insights, and spread the word.

3) You can use basic HTML/xHTML tags.

4) All comments are DoFollow—please use the section professionally.

5) Kindly mention your name or brand below your comment.

6) Constructive suggestions for improvement are always welcome.


Thanks for visiting Samee Articles.

========================================

Best Regards,

Samee U. Feroz

 
Copyright © 2011-2026. Samee Articles - All Rights Reserved
Proudly powered by Blogger