PHP Types

Types are an essential part of any languae. Types means variable types that defines which type of data we are using. There are six PHP types. These are:
  1. bolean
  2. string
  3. float
  4. integer
  5. array
  6. object

Now I’ll eleborate them one by one.

Boolean: This is the very simple type. This type determine the truth values. In truth values, there may be  “false” or “true”. Note that both are case sensitive.

String: Php doesn’t support Unicode, it supports “256 character set”. String is a combination of characters and words, each chracter is a byte. String can be specifies in single quotes and double quotes.

Flaot: We also called floating numbers as doubles, real numbers and float. The sytax of floating numbers can be following as
$test = 3.4;
$test = 3.4e3;
$test = 7E-9;

Integer: Integer can be any number but 3.4 like numbers are not allowed. It can range from (0 to 10) and (-10 to 0).

Array: Array is like a table. It have values and every value is associated to a unique key. For example:
$a = array(‘a’,’b’,’c’);
$a[0] = a;
$a[1] = b;
$a[2] = c;
We can also use multi-dimensional arrays. For Example
$a[0][0] = 3;

Object: We often use objects in a class, these objects can also be calles as instances. For example.
Class test
                Function hello()
                                echo “This is my first class”;
$a = new test;
Now variable $a is a object of the class test, that are accessing the class methods.

No comments:

Post a Comment