Tuesday, June 26, 2012

PHP learning - Working With Data(1)

In previous lesson, we have learned variables. In php, variables can store data in different types. The different types of data are:
Interger: A whole number (no fractions), such as 10, 0, -43Floating point number: A number that include decimal places, such as 5.36, 4.232Character string: A series of single characters, such as "good", "hello"Boolean: a true or false valuePhp is smarter than you think, it evaluate the variable you stored and will assign an approriate data type to the variable. For example:
$number=2 ; # php store it as interger
$sports="football" #php store it as character string

You can also tell php the type of data you want to store, look at the following example:
$number=(int) $var1; #you are telling php to store $var1 as interger
$sports=(string)$var2; #you are telling php to store $var2 as character string

To find out the type of a variable, use var_dump:
var_dump($var1) #you are asking php what type of data is variable1

PHP provides a shortcut for adding 1 to a variable, for example:
$number=$number+1; can be rewrite as $number++;
$number=$number-1; can be rewrite as $number--;
Other forms of shortcut includes:
$number+=3;
$number-=2;
$number*=4;
$number/=5;


View the original article here

No comments:

Post a Comment