PHP Tutorial
How do I create a numeric variable using PHP?
A variable is a name that represents a value. For example, you could have the
variable $myAge represent the value 29. A numeric variable is often used to
store a value that may change, such as the result of a calculation or data
retrieved from a database. The following is an example of creating a numeric
variable.
<html>
<head>
<title>Numeric Variable</title>
</head>
<body>
My current age is <? //The $ must be followed by a letter or an underscore
character(_)
$myAge = 35; // Prints out on the screen the output, value, of myAge
print $myAge;
?>
</body>
</html>
In PHP you do not need to explicitly declare the type of a variable you want to
create. For example, the same variable can be used to represent first an integer
and then a floating-point number with no data type declarations.
$a = 1;
$a = $a + 1.5;
You can use exponential notation to specify a very large or very small number as
the value of a variable. In this following example, $a is equal to 123000 and $b
is equal to 0.0000123.
$a = 1.23e5;
$b = 1.23e-5;
When working with numbers, PHP assumes you are working in base 10, or decimal
notation. PHP also supports base 8, or octal notation, and base 16, or
hexadecimal notation. To specify a value in octal notation, place a zero (0)
before an octal number.
//The print out will be 16
$a = 020;
print $a;
To specify a value in hexadecimal notation, place a zero (0) and the letter "x"
before a hexadecimal number.
//The print out will be 16
$b = 0x10;
print $b;