Difference between revisions of "Understanding PHP Variable Types"

From Techotopia
Jump to: navigation, search
(New page: In this chapter we will look at the PHP ''integer'', ''string'', ''float'' and ''boolean'' variable types. Since the the ''array'' and ''object'' types are slightly more complex entities w...)
 
Line 1: Line 1:
 
In this chapter we will look at the PHP ''integer'', ''string'', ''float'' and ''boolean'' variable types. Since the the ''array'' and ''object'' types are slightly more complex entities we will devote subsequent chapters to them later in the book (see [[Using Arrays in PHP]] and [[PHP Object Orientation]]).
 
In this chapter we will look at the PHP ''integer'', ''string'', ''float'' and ''boolean'' variable types. Since the the ''array'' and ''object'' types are slightly more complex entities we will devote subsequent chapters to them later in the book (see [[Using Arrays in PHP]] and [[PHP Object Orientation]]).
 +
 +
== The PHP Integer Variable Type ==
 +
 +
Integer variables are able to hold a whole number in the range of -2147483648 to 2147483647. Negaitve values can be asssigned by palcing the minus (-) sign after the assigment operator and before the number. If tyhe value assigned to an integer type variable moves outside the range, either via assignment or mathematical calculation, the variable type is automatically converted to a floating point type.
 +
 +
The following examples assign integers to variables:
 +
 +
<pre>
 +
<?php
 +
 +
$myInteger = 10;
 +
 +
$myNegative = -13457231;
 +
 +
?>
 +
</pre>

Revision as of 19:01, 25 May 2007

In this chapter we will look at the PHP integer, string, float and boolean variable types. Since the the array and object types are slightly more complex entities we will devote subsequent chapters to them later in the book (see Using Arrays in PHP and PHP Object Orientation).

The PHP Integer Variable Type

Integer variables are able to hold a whole number in the range of -2147483648 to 2147483647. Negaitve values can be asssigned by palcing the minus (-) sign after the assigment operator and before the number. If tyhe value assigned to an integer type variable moves outside the range, either via assignment or mathematical calculation, the variable type is automatically converted to a floating point type.

The following examples assign integers to variables:

<?php

$myInteger = 10;

$myNegative = -13457231;

?>