Data Types in PHP
Posted by chaabant on Dec 28, 2007
Data Types in PHP
In php there is different types of data , the most used are :
string // binary data
boolean // true or false
int // Integer
Integers are numbers; Positive and negative numbers can be expressed with it).
Boolean contain two values: false or true .
String Are text , it could be also a collection of binary data (contents of a doc file or image or even mp3 file)
Declaring Variables in PHP
To declare variables in php all what you need to do is place a $ at the beginging of a name that you will give to your variable to refer it .
ex :
-
$my_number = 13 ; // declaring variable called my_number
-
-
$my_name = "Chaaban"; // declaring a variable called "my_name" that contain : Chaaban ;
-
-
$whatever = true ; // declaring a variable called "whatever" that contain a boolean value of true .
php is different than other languages , you can declare a variable that contain a number and later replace it with a string or boolean .
ex :
-
$x = 10 ;
-
-
// random codes
-
// …
-
// random codes
-
-
$x = "HELLO WORLD";
-
Invalid names when Declaring a Variable
Variables must be named using only letters (a-z, A-Z), numbers and the underscore character; Their namesmust start with either a letter or an underscore, and are one of only two identifier types in PHP that are case sensitive
-
$txt = ’valid’ ; // valid
-
$_txt = ’valid’; // Valid variable name
-
$10txt = ’invalid’; // Invalid varianle name since it starts with a number