Wednesday, July 6

Data Types in PHP and other notes

Following is the excerpts i read from a php programming book.

In php, we have scalar data types and compound data types.
Scalar data types means data that contains only a single value. Php has these scalar data types
  1. Integer - A number eg. 15
  2. Float - A floating point number eg. 8.25
  3. string - A series of characters eg. "hello world"
  4. Boolean - Represents either true or false eg. true
Compound data is data that can contain more than a value.
  1. Array - An ordered map (Contains names or numbers mapped to values)
  2. Object - A type that can contain properties or methods.
Apart from these, php also contains special data types.
  1. Resource - Contains reference to an external resource, such as a file or database.
  2. Null - May contain only null as a value,meaning the variable explicitly does not contain any value.
Php is known as a loosely typed language. It does not care about the type of data being stored in a variable. It converts a variables data type automatically, depending on the context in which the variable is used.

Other Notes
Php considers the following values to be false
  1. The literal value false
  2. The integer zero (0)
  3. The float zero (0.0)
  4. An empty string (" ")
  5. The string zero ("0")
  6. An array with zero elements
  7. The special type null including any unset variable

Be the first one to Comment!!!

Post a Comment