Different types of Operators using in PHP they are Arithemtic Operators,Assignment Operators,Comparison Operators,Increment/decrement Operators,Logic Operators,String Operators
Arthimetic Operators
Example Name Result
-$a Negation Opposite of $a.
$a - $b Subtraction Difference of $a and $b.
$a + $b Addition Sum of $a and $b.
$a / $b Division Quotient of $a and $b.
$a % $b Modulus Remainder of $a divided by $b.
$a * $b Multiplication Product of $a and $b.
Assignment Operators
The basic assignment operator is "=". Your first inclination might be to think of this as "equal to". Don't. It really means that the left operand gets set to the value of the expression on the rights (that is, "gets set to").
Example :
<?php
$a = ($b = 4) 5; // $a is equal to 9 now, and $b has
been set to 4.
?>
Comparison Operators
PHP using Comparison operators in C,C++,java except "===" operator
Example Name Result
$a == $b Equal TRUE if $a is equal to $b.
$a === $b Identical TRUE if $a is equal to $b, and they are of the same type.
$a != $b Not equal TRUE if $a is not equal to $b.
$a <> $b Not equal TRUE if $a is not equal to $b.
$a !== $b Not identical TRUE if $a is not equal to $b, or they are not of the same type.
$a < $b Less than TRUE if $a is strictly less than $b. $a >= $b Greater than or equal to TRUE if $a is greater than or equal to $b.
Increment and Decrement Operator
++,-- operators
Example Name Effect
++$a Pre-increment Increments $a by one, then returns $a.
$a++ Post-increment Returns $a, then increments $a by one
--$a Pre-decrement Decrements $a by one, then returns $a.
$a-- Post-decrement Returns $a, then decrements $a by one.
Example:
<?phpecho "<h3>Postincrement</h3>";
$a = 5;
echo "Should be 5: " . $a . "<br />\n";echo "Should be 6: " . $a . "<br />\n";
echo "<h3>Preincrement</h3>";
$a = 5;
echo "Should be 6: " . $a . "<br />\n";echo "Should be 6: " . $a . "<br />\n";
echo "<h3>Postdecrement</h3>";
$a = 5;
echo "Should be 5: " . $a-- . "<br />\n";
echo "Should be 4: " . $a . "<br />\n";
echo "<h3>Predecrement</h3>";
$a = 5;
echo "Should be 4: " . --$a . "<br />\n";
echo "Should be 4: " . $a . "<br />\n";
?>
Arithemetic Operator on Character Variable
Example :
<?php
$i = 'W';
for ($n=0; $n<6; $n )
{
echo $i . "\n";
}
?>
The above example will output:
X Y Z AA AB AC
String Operators
There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side.
Example :
<?php
$a = "Hello ";
$b = $a . "World!"; // now $b contains "Hello World!"$a = "Hello ";
$a .= "World!"; // now $a contains "Hello World!"
?>
Logical Operators
Example Name Result
$a and $b And TRUE if both $a and $b are TRUE.
$a or $b Or TRUE if either $a or $b is TRUE.
$a xor $b Xor TRUE if either $a or $b is TRUE, but not both.
! $a Not TRUE if $a is not TRUE.
$a || $b Or TRUE if either $a or $b is TRUE
$a && $b And TRUE if both $a and $b are TRUE.
tag:-PHP Operators,Arithmetic Operators,Relational Operators,Increment and Decremet,String Operators,Logical Operatos
Articles
- Articles(C#.NET) (3)
- ASP.NET (6)
- Asp.Net(Email) (1)
- Asp.net(Image) (2)
- Asp.Net(Web.Config) (2)
- C#.NET (5)
- C#.NET Threading (3)
- C#.NET(ASP.NET) (4)
- Comments in PHP (1)
- Encryption In PHP (1)
- iPhone (Articles) (1)
- JavaScript (1)
- Json with PHP (1)
- LINQ (1)
- PHP (2)
- PHP Constant (1)
- PHP Operators (1)
- PHP Print Command (1)
- PHP Tutorial (2)
- Strings In PHP (1)
- Variable Declaration In PHP (1)
- WPF (1)
- XAML (2)
About Me
Help Link
Followers
Posted by
Sreejith A.K
Thursday, August 27, 2009
comments (0)
Labels:
PHP Operators
Subscribe to:
Posts (Atom)