PHP Variables and Datatypes
What is a variable? (You are kidding ... aren't you?)
How to set a variable in PHP?
This is how you do it ...
$variableName = value;
Letters, numbers, underscore (_) are allowed in variable names.
Spaces ( ), non-alphanumeric characters are NOT allowed in variable names.
Variable names CANNOT start with a number!
Here are the basic datatypes in PHP. The value of a variable can be one of these datatypes:
1. Integer eg. 12345
2. Double eg. 123.45
3. String eg. 'string' or "string"
4. Boolean either true or false (PHP4 onwards)
Note that PHP does not impose strong type checking. (i.e. A variable may take on different datatypes at different points of execution.)
<?php
// Defines an integer
$noOfPeople = 12345;
// Defines an double
$priceOfProduct = 123.45;
// Defines a boolean
$userHasRegistered = true;
// Defines a string
$welcomeMessage = "Hello World";
?>
(... You mean you really don't know what a variable is? ... hmmm ... well ... treat it as a box containing a value which may vary. )
How to set a variable in PHP?
This is how you do it ...
$variableName = value;
Letters, numbers, underscore (_) are allowed in variable names.
Spaces ( ), non-alphanumeric characters are NOT allowed in variable names.
Variable names CANNOT start with a number!
Here are the basic datatypes in PHP. The value of a variable can be one of these datatypes:
1. Integer eg. 12345
2. Double eg. 123.45
3. String eg. 'string' or "string"
4. Boolean either true or false (PHP4 onwards)
Note that PHP does not impose strong type checking. (i.e. A variable may take on different datatypes at different points of execution.)
<?php
// Defines an integer
$noOfPeople = 12345;
// Defines an double
$priceOfProduct = 123.45;
// Defines a boolean
$userHasRegistered = true;
// Defines a string
$welcomeMessage = "Hello World";
?>
(... You mean you really don't know what a variable is? ... hmmm ... well ... treat it as a box containing a value which may vary. )

0 Comments:
Post a Comment
<< Home