iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 12, 2008
Film Makers, Bands and Comedians Welcome on MySpace
About
 
May 12, 2008
Software Engineering for Ajax
WebReference.com
 
May 12, 2008
What is the Head Tag For?
About
 
May 11, 2008
Improving accessibility for motor impaired users
WebDevTips UK
 
May 11, 2008
10 ways to orientate users on your site
WebDevTips UK
 
May 11, 2008
Web Design Clinic - Rros restoration camp 2006
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP /Introduction to PHP

PHP Lesson Two - Variables 

  Views:    25010
  Votes:    4
by James N Hitz 1/23/04 Rating: 

Synopsis:

Lesson 2: takes you into the realm of PHP variables, how they are defined, concatenation and PHP operators.
Pages: firstback1 2 3 5 6 7 8 9 10 forwardlast
The Article

Assigning Values to Variables

Assigning a Value to a variable is simple. Check this out:

$item = "Book";
$quantity = 5;
$unit_cost = 23.55;
$tax = .01;
$total = ($quantity * $unitcost) * (1 + $tax);
$pricePerItem = $total/$quantity;

Here the variables are getting their value from a direct assignment ie:

$variable = value;

or from a compound statement:

$variable = (formula) * (another formula)...

When making formulas (Expressions) we make use different PHP operators. It is wise to note that there is a well defined order of precedence. This means that some PHP operators are more Operators than others (ever read 'Animal Farm'?). Hey don't worry if some people get the VIP treatment when you don't. This behaviour extends to PHP operators too.

For the 4 most common arithmetical operators, the order is thus:

Multiplication -> Division -> Addition -> Subtraction
      *              /            +           -

This order of precedence can be over-ridden using brackets which work from inside-out. Meaning. The innermost brackets are evaluated first and then the outer brackets and eventually the outermost... and so on until all the brackets are evaluated. You must have dome mathematics in school and have probably heard of BODMAS (or BEDMAS) (We here use BOMDAS and BEMDAS. I assume you are comfortable with this.

Pages: firstback1 2 3 5 6 7 8 9 10 forwardlast

Similar/related articles:


 
  Sponsors