Make your own free website on

Visit the Official PHP Website
Search this Site

PHP Programming

By James N Hitz

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!!!

<< What are Scalars | Predefined Variables >>