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 4 5 6 7 9 10 forwardlast
The Article

Clowns we become - The Art of Type Juggling.

A good clown should always be able to juggle, spot a big red nose and sing soprano through his... (Come on. Stop It!). In PHP we can also juggle between data types (albeit without the soprano part of it) nothing short of real clowns.

Take a look at the following code snippet:

$pots = 7;
$kettles = "4";
$spoons = 14.3;
$milk = "14.5 pints";
$totalUtensils = $pots + $kettles + $spoons;
$totalGoods = $totalUtensils + $milk;

$pots is an integer with a value of 7. Coz it's a whole number (of course. What do I take you for.)

The variable $kettles is a string with a value of 4. This is because the value assigned is enclosed in double quotes. Every time a value is enclosed in double quotes (" ") it is string. Remember?

$spoons is a floating-point number with a value of 14.3 (Where did this 1/3 spoon come from anyway).

$totalUtensils is thus a calculation summing up a numeric string, an integer and a floating point number. The result is a floating point number containing the value 25.3.

$milk is a string who's value has a numerical part. So when it is used in a mathematical formula, the numeric value is extracted. That is why the variable $totalGoods now contains 39.8 (the result of 25.3 + 14.5).

See!? We are real jugglers now - successfully capable of juggling scalars of different flavours. Phew! Life is not so tough after all, wouldn't you say!

And Now... Predefined Variables!!!

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

Similar/related articles:


 
  Sponsors