Total members 11895 |It is currently Sun Dec 22, 2024 10:48 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





I will start with you by the list of operators type :
    * Assignment Operators
    * Arithmetic Operators
    * Comparison Operators
    * String Operators
    * Combination Arithmetic & Assignment Operators

1- Assignment Operators


This is done using "="
For example
Code:
   <?
        $x=5;
        $y=$x;
         
    ?>


now both x , and y have the value 5

2 - Arithmetic Operators



Operator English Example

Code:
   
    +  Addition            1 + 2
     -    Subtraction           4 - 2
     *  Multiplication            2 * 2
    /     Division              20 / 4
    %  Modulus                  7 % 3


Code:
<?php 
$addition 
2
$subtraction 2
$multiplication 2
$division 20 4
$modulus 3
echo 
"addition: 1 + 2= ".$addition."<br />"
echo 
"subtraction: 4 - 2 = ".$subtraction."<br />"
echo 
"multiplication:  2* 2 = ".$multiplication."<br />"
echo 
"division: 20 / 4 = ".$division."<br />"
echo 
"modulus: 7 % 3 = " $modulus ;
   


the output is :
Code:
addition: 1+ 2 = 3
subtraction: 4 - 2 = 2
multiplication: 2 * 2 = 4
division: 20 / 4 = 5
modulus: 7 % 3 = 1


3- Comparison Operators


Operator English Example Result
== Equal To $x == $y false
!= Not Equal To $x != $y true
< Less Than $x < $y true
> Greater Than $x > $y false
<= Less Than or Equal To $x <= $y true
>= Greater Than or Equal To $x >= $y false


4. String Operators


The dot (.) Operator between two strings as we saw before . like :
Code:
   $mstring1="Welcome to ";
   $mstring2="Codemiles Forums";
    echo $mstring1.$mstring2;


the output is :
Code:
Welcome to Codemiles Forums



5- Combination Arithmetic & Assignment Operators


If you want to increase a variable by some value . you can do the follow :
$x=$x+1;

or using short hand :
$x+=1;

here all some examples
Code:
Operator   English    Example    Equivalent Operation
+=          Plus Equals     $x += 1;    $x = $x + 1;
-=           Minus Equals     $x -= 1;    $x = $x - 1;
*=          Multiply Equals    $x *= 1;    $x = $x * 1;
/=           Divide Equals    $x /= 1;    $x = $x / 1;
%=         Modulo Equals    $x %= 1;    $x = $x % 1;
.=              Concatenate Equals    $my_str.="codemiles";    $my_str = $my_str . "codemiles";



before i close this topic i will talk about some thing which is . how to do pre/post increment and decrement . It is more shorter for adding or subtracting 1 from a variable.

$x++ is equal to $x+=1 or $x=$x+1
$x-- is equal to $x-=1 or $x=$x-1

Is $x++ different from $++x in your code ? Yes :confused:

you specify the increment before or after the line of code is executed
Example
Code:
$value=10;
  echo "my value is ".$x++;
echo "my value is ".$x;
$value=10;
  echo "<br/>my value is ".$++x;
echo "my value is ".$x;



the output is :
Code:
my value is 10 my value is 11
my value is 11 my value is 11


i wish it is clear :wink:

thanks



_________________
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 operators
 Equality Operators     -  
 C++ Increment Operators     -  
 Using Assignment Operators     -  
 shortcut operators     -  
 difference between the >> and >>> operators     -  
 Bitwise operators     -  
 using bit-wise operators in c++     -  
 bitwise operators usage in C++     -  
 Use the boolean compare operators     -  
 Comparison Operators in java     -  



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