Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

PHP

PHP OPERATORS:-

Operators are used to perform operation on variable and values.

PHP have the 7-Operators :-

  • Arithmetic Operator
  • Assignment Operator
  • Comparison Operator
  • Increment/Decrement Operator
  • Logical Operator
  • String Operator
  • Array Operator

PHP Arithmetic Operator:-

PHP Arithmetic Operator are used with numeric value to perform arithmetic operation like:- Addition, Subtraction, Multiplication, Division, Remainder ..

Opertaor Name Example Result
+addition$x + $ySum of $x and $y
-Subtraction$x - $yDifference of $x and $y
/Division$x / $yDivision of $x and $y
*Multiplication$x * $yMultiplication of $x and $y
%Modulus$x % $yRemainder of $x and $y
**Exponentiation$x ** $yRaising $x to the $y'th power


PHP  Assignment Operator:-

PHP assignment operator is used with numeric value to assign value of one variable to other variable.

Opertaor Name Example Result
=Equal$x = $yValue of $y is set to variable $x.
+ =Addition
($x + = $y)
$x = $x + $yAddition of $x and $y and result store to $x.
- =Subtraction
($x - = $y)
$x = $x - $ySubtraction of $x and $y and result store to $x.
* =Multiplication
($x * = $y)
$x = $x * $yMultiplication of $x and $y and result store to $x.
/ =Division
($x / = $y)
$x = $x / $yDivision of $x and $y and result store to $x.
%Modulus
($x % = $y)
 $x = $x % $y     Remainder of $x and $y and result store to $x.

Example:-


<?php
$x = 20;  
$x += 100;

echo $x;
?>
 
Output: 120





PHP Comparison Operator: -

PHP Comparison operator are used to compare two values (value would be either number or string).

Opertaor Name Example Operation
= =Equal$x = = $yCheck the value of $x is equal to $y or not.
= = = Identical$x = = = $yCheck the value of $x is equal to $y and of same data-types(string, int char, etc..).
! =Not Equal$x ! = $yReturns true if $x is not equal to $y.
< >Not Equal$x < > $yReturns true if $x is not equal to $y.
! = =Not Identical$x ! = = $yCheck the value of $x is not equal to $y or they are not of  the same data-types(string, int char, etc..).
Greater than $x > $y     Returns true if $x is greater than $y.
<Less than $x <  $y     Returns true if $x is less than $y.
> =Greater than or Equal to    $x > = $y     Returns true if $x is either greater than or equal to $y.
< =Less than or Equal to    $x < = $y     Returns true if $x is either less than or equal to $y.


One of the most important operator in php is 'SCOPE RESOLUTION OPERATOR(::)' 
Define :-  Scope Resolution Operator or double Colon is a Token that allows access to Static, Contant, Overridden property or method of a class.
Ex 1:  :: from outside the class {DefineClass.php}
<?php
class dog
{
const color = 'My dog is of white color{form DefineClass.php}';
}
echo dog::color;
?>


OUTPUT :-My dog is of white color
Ex 1:  :: from inside the class   {AccessDefineClassMember.php}
<?php include'DefineClass.php' ?>
<?php
class snake extends dog
{
    public static $length='snake is longer than my dog';
    public static function doublecolon() {
        echo parent::color.'<br>';
        echo self::$length.'<br/>';
    }
}
//$classname = 'snake';
//$classname::doublecolon(); // for PHP5.3
snake::doublecolon();
?>


OUTPUT :-   My dog is of white color{form DefineClass.php}
                      snake is longer than my dog

Three special keywords selfparent and static are used to access properties or methods from inside the class definition.



No comments:

Post a Comment