Total members 11895 |It is currently Wed Dec 18, 2024 7:36 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





if statement :
If statement in PHP is like other programming language .if statement in your code means if something is correct do something.

Code:
<?php 
 if 
(condition )  
   
{ 
     
//do something 
    }
  


when the condition is true , the code between bracket will be implemented .

Here a simple example (true condition):

Code:

  $myname
="dodo";
   if($myname=="dodo") 
     
{
        echo "oooooh, your name is dodo";
     }
   <br/>welcome ..
 
 


the output is :
Code:

   oooooh
, your name is dodo 
   welcome 
..
 
 


Here a simple example (false condition):

Code:

  $myname
="toto";
   if($myname=="dodo") 
     
{
        echo "oooooh, your name is dodo";
     }
   <br/>welcome ..
 
 


the output is :
Code:
   welcome ..



elseif statement:


In the case your condition is false ,you can make a second check after the first if.

for example :
Code:

  $myname
="toto";
   if($myname=="dodo") 
     
{
        echo "oooooh, your name is dodo";
     }
   elseif($myname=="toto")
     {
        echo "oooooh, your name is toto";
     }

   <br/>welcome ..
 
 


the output is :
Code:

   oooooh
, your name is toto
   welcome 
..
 
 


else statement :

When a condition is false other code will be executed and it is the one between else brackets .

for example :
Code:

$myname
="msi";
   if($myname=="dodo") 
     
{
        echo "oooooh, your name is dodo";
     }
   else 
     
{
        echo "oooooh, your name is $myname";
     }

   <br/>welcome ..
 
 


the output is :
Code:
   oooooh, your name is msi
   welcome ..



ok , here a general example contain if ,elseif and else statement :
Code:

  $myname
="toto";
   if($myname=="dodo") 
     
{
        echo "oooooh, your name is dodo";
     }
   elseif($myname=="toto")
     {
        echo "oooooh, your name is toto";
     }
     else 
     
{
        echo "oooooh, your name is $myname";
      }
   <br/>welcome ..
 
 


the output is :
Code:
   oooooh, your name is toto
   welcome ..



Another example :

Code:

  $myname
="Ali";
   if($myname=="dodo") 
     
{
        echo "oooooh, your name is dodo";
     }
   elseif($myname=="toto")
     {
        echo "oooooh, your name is toto";
     }
     else 
     
{
        echo "oooooh, your name is $myname";
      }
   <br/>welcome ..
 
 


the output is :
Code:
   oooooh, your name is Ali
   welcome ..



i hope it is a good article :grin:



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : PHP if statement and else if
 difference between break statement and a continue statement     -  
 difference between a while statement and a do statement     -  
 Need help with if statement     -  
 while Statement in php     -  
 The do...while Statement     -  
 Using the for Statement     -  
 global statement in php     -  
 Using the continue Statement     -  
 Define statement     -  
 JOptions and If - Else statement     -  



Topic Tags

PHP Basics
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com