VisualBuilder
  Home > Php > Tutorials > Operators - PHP Tutorial
Tell a friend
Link to us
Total Members
      Members: 84661
     
Sitemap Forum Chat
Home
PHP Tutorial Home
1 . An Introduction to PHP
2 . Getting Started With Variables
3 . Comments in PHP
4 . Operators
5 . The Switch Statement
6 . Logical Operators
7 . Boolean Values
8 . Working with HTML Forms
9 . Programming Loops
10 . Arrays in PHP
11 . String Manipulation
12 . Create your own Functions
13 . Date and Time Functions in PHP
14 . Working With Files In PHP
 
 
PHP Home
PHP Members (3076)
PHP Member Articles ( 9 )
PHP Discussion (11)
PHP Q & A ( 13 )
- PHP Ask Question
- PHP Questions
- PHP Unanswered Questions
PHP Resources
PHP Source Code (463)
PHP Articles (118)
PHP Blogs (30)
PHP Jobs (0)
PHP Components (24)
PHP Books (3)
PHP Websites (29)
PHP News (17)
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.Net Security,Internationalisation And Deployment
ASP.NET Tutorial
C# Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (451 )
Source Code (3275 )
Articles (359 )
Books (372 )
Components (1596 )
News (892 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise

Php Tutorial
 Operators
  << Prev: Comments in PHP Next: The Switch Statement >>

Operators

1. Comparison Operators



== Has the same value e.g $variable == $variable2


!=  Does NOT have the same value  e.g $variable != $variable2


>   Less than e.g $variable > $variable2


<   Greater than e.g $variable < $variable2


>= Greater than or equals to e.g $variable >= $variable2


<=  Less than or equals to e.g $variable <= $variable2



Conditional Logic 


1. If Statements    


You learn that variables are used to store some information that you can use later whenever required,you can save text and numbers. You store information so that you can do something with them. If you have stored a username in a variable and need to check if this is a correct username. For this you need to use "IF" statement.


if(condition)


{


// Start with { and end with } and any thing written between these two {} are execute under if condition


}



$username = "Nemo";


$number = "19051981";



if( $username == "Nemo" )


{


    echo "Correct username";


}


if( $username != "Doree" )


{


    echo "If condition OK as our variable has Nemo saved in it and we are comparing Nemo with Doree that are two different strings so we are in if statement.";


}


if( $number == "2031" ) // Did not go into this statement


{


    echo " ";


}



if( $number == "19051981" )


{


    echo "Correct number";


}


$number2 = "19051981";


if( $number == $number2 )


{


    echo "Correct number";


}



" == (Double equal sign)" used to compare two strings or numbers.
" != (Sign of Exclamation and equal sign)" used to compare if two strings or numbers are not equal to each other


2. if ... else


IF ELSE statement used when your IF statement doesnot comes true than you use the ELSE part. For example if the values of two variables are same you want to print out TRUE (i.e variables have same values) and if the values of the two variabales are not equal (i.e variables have different values) than you want to print FALSE,here ELSE part of IF used.


<?


$username = "Nemo";


$number = "19051981";



if( $username == "Nemo" )


{


    echo "TRUE";


}


else


{


    echo "FALSE";


}



if( $username != "Doree" )


{


    echo "TRUE";


}


else


{


    echo "FALSE";


}


?>


<?


$usaFlag = 0;
$ukFlag = 1;


if ( $usaFlag == 0 )


{
    echo "<IMG SRC=images/usaFlag.jpg>";
}
else


{
    echo "<IMG SRC=images/ukFlag.jpg>";
}


?>



3. if ... else if


<?


$usaFlag = 0;
$ukFlag = 1;


if ( $usaFlag == 1 )


{
    echo "<IMG SRC=images/usaFlag.jpg>";
}
else if ( $ukFlag == 1 )


{
    echo "<IMG SRC=images/ukFlag.jpg>";
}


else


{


    echo "No value equal to 1 found.";


}


?>


 


 


  << Prev: Comments in PHP Next: The Switch Statement >>
Php Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
 
ADVERTISEMENT
Partner List
Code Project
ASP Alliance
More
 
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising