Monday, 25 May 2009

PHP Variable and Value Types

Variable is a representation of a particular value, such as blue or 1234.

Notice: To create a variable, we should remember these steps:
  1. Thinking of a good name
  2. Putting a dollar sign ($) in front of the name.
  3. Using equals sign (=) after the name to assign a literal value to that variable and put the value in quotation marks.
  4. Assigning the value to a variable is an instruction and should be terminated with a semicolon (;).
Eg: $username = "Hung"

Variable names can be recognized by:
  • They begin with a dollar sign ($)
  • can not begin with a numeric character
  • can contain numbers and the underscore (_) character
  • they are case sensitive.
There are 2 main types of variables in PHP code: scalar and array
  • Scalar variables contain 1 value at a time
  • Array contains a list of values or even another array.
When we assign a value to a variable, we always assign to one of the following types:
  • Integer: whole number (without decimals)
Eg: 1, 99, 200,...
  • Floating point numbers ("float" or "double"): number with decimals
Eg: 1.4, 3.3, 444.33
  • String: text or numeric information, specified within double quotes (" ") or single quote (' ').
My practice code:



and result

No comments:

Post a Comment