Ajax Tutorials, PHP Tutorials, Javascript Tutorials, Visual Basic.Net Training, XHTML tutorials, php script library, PHP Codes, Programming tutorials, web development tutorials
Web Development Tutorials, Programming Tutorials, PHP Script Index
Home | Forums | Downloads | Books | Submit Content | Links

Programming Articles

  PHP articles
  MySql articles
  Visual Basic.Net articles
  Java articles
  ASP articles
  ASP.Net articles
  Visual Basic articles
  CSS articles

Programming Tutorials

  PHP tutorials
  MySql tutorials
  Visual Basic.Net tutorials
  Java tutorials
  ASP tutorials
  ASP.Net tutorials
  Visual Basic tutorials
  HTML tutorials
  CSS tutorials

Programming Source Codes

  PHP scripts
  Visual Basic.Net scripts
  JavaScript scripts
  ASP scripts
  ASP.Net scripts
  Visual Basic scripts

Our Partners

  Free Resources
  Publisherbank
  Free Link Directory
  PHP Magazine
  Webmaster Passion
  Search Engine Bank
  Free Directory Site
  Free PHP Scripts
  Links Shopping Mart
  Variety Bazar
  Urdu Office Tutorials
  Evernew Scripts
  Evernew Scripts
  Evernew Directory
  Our Achievements
  Web templates
  Buy and Sell Templates
  Text Link Traders
  Directory Metro
  Gifts Choice
  Valentines Ecards
  Template Directory

Operators in PHP

Date:2006-02-13

PHP operators are very similar in different programming languages like C++, JavaScript, Java. Operator is a symbol that is used to perform any operation. Operators are used to perform arithmetic or logic operations, there are many types of operators.
1) Arithmetic operators
2) Comparison operators
3) Logical operators

Arithmetic Operators

Arithmetic operators are used to perform any arithmetic operation (addition, division, subtraction, multiplication). In PHP following operators are used

Operator Example Functionality
+ 2+4 Addition of 2 or more than 2 values
- 8-2 Substraction of 2 or more than 2 values
* 5*7 Multiplaction of 2 or more than 2 values
/ 18/3 Division of 2 or more than 2 values
% 76%10 Modulus of 2 or more than 2 values

Example

<body>
<?php
var $val1=35;
var $val2=38;
var $val3;
val3=$val1+$val2;

echo($val1+”+”+$val2+”=”+$val3);
?>

The output of this example is below:

35+38=73

Comparison Operators

Comparison operators are used to compare two or more value. A double equal sign (==) compares two values but A single equal sign sets a value. Comparison operators are used inside conditional statements and evaluate to either true or false.  Following comparison operators are used in PHP.

Operator Example Functionality
== a==b variable a is equal to variable b
!= a!=b variable a is not equal to variable b
< a<b variable a is less than variable b
> a>b variable a is greater than to variable b
<= a<=b variable a is less than or equal to variable b
 => a=>b  variable a is greater than or equal to variable b 

 

<html>
<head>
<title>PHP Example</title>
</head>
<body>
<?php
$a= 8;
$b= 3;
$c= 3;
echo $a ==$b,"<br>";
echo $a != $b,"<br>";
echo $a <$b,"<br>";
echo $a > $b,"<br>";
echo $a >=$c,"<br>";
echo $b <=$c,"<br>";
?>
</body>
</html>

Logical Operators

Logical operators are used to evaluate several comparisons, by combining their possible values.

Operator Example Functionality
&& (5>3) && (5<7) Returns true when both conditions are true.
|| (5>3)||(5<7) Returns true when at least one of the two conditions is true.
! !(5>3) Denies the value of the expression.

<head>
<title>PHP Example</title>
</head>
<body>
<?php
$a = 8;
$b = 3;
$c = 3;
echo (a ==b) && ($c > $b),"<br>";
echo ($a == $b) || ($b == $c),"<br>";
echo !($b <= $c),"<br>";
?>
</body>
</html>

Note: You can easily understand  comparison and logical operators in next chapter conditional statement.

 



Desclaimer | Privacy Policy | Submit Content | Links | Link to Us | Sitemap |Contact Us
Copyright Programming Tutorials, Web Development Tutorials, Source codes © All Rights are Reserved.
Powered By Evernew Solutions

Credit Card Consolidation - Credit Card - Mortgage - Scottsdale Landscaping