PHP learning experience

My personal learning experience on php. Basic php scripting language for beginners

Tuesday, March 28, 2006

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:
  1. Interger: A whole number (no fractions), such as 10, 0, -43
  2. Floating point number: A number that include decimal places, such as 5.36, 4.232
  3. Character string: A series of single characters, such as "good", "hello"
  4. Boolean: a true or false value
Php 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;

0 Comments:

Post a Comment

<< Home