PHP   Data   Types

PHP Support some data types :- Integer, Float, boolean, String, Array, Object, null

PHP Integer data type

  • integer data type is a number without decimals.
  • integer data type must not have a decimal point (look like 2323.232 ) .
  • integer data type support both positive and negative values.
  • size of an integer is platform-dependent.
  • php does not support unsigned integers.

integers values can be represent in three formats: decimal(base 10), hexadecimal (base 16 - prefixed with 0x), octal (base 8 -prefixed with 0).

integer size can be determined using the constant php_INt_size, and maximum value using the constant php_int_max.

                     $x    = 40;       // a decimal number
                     $xx   = -10000;   // a negative number
                     $xxx  = 0x1A;      // a hexadecimal number (equivalent to 26 decimal)
                     $xxxx = 0123;      // a octal number (equivalent to 83 decimal)
                     echo   "x value = $x";
                     echo   "xxx value = $xxx";
                     echo   "xxxx value = $xxxx";
                     echo   "integer size = ".php_Int_size;
                     echo   "integer maximum value = ".php_int_max;

PHP Floating Point data type

floating point value define with a decimal point (e.g 34.34 , 343434.3434, .34343).

a floating point number can be represent in exponential or scientific form (e.g 343e4, 3e-10, 34e3).

the size of a float is platform-dependent.

                  $y   = 101.34;       //floating point  number
                  $yy  = 34e2;      //scientific notation
                  $x   = 343434e-6;     

                  echo  " float y  value  = $y";
                  echo  " float yy value  = $yy";                 

PHP String data type

a String value is a sequence of zero or more characters. (e.g "website - w3webtutorial" )

a string value always enclosed within single quotes ' or double quotes " .

any type of data you can put inside single ( '2a$' ) or double quote ("2a#$").

                  var        name   ='sandeep';

                  var     lastname ="kumar nehra";

you can use quotes inside a string, as long as they don't match the quotes surrounding the string:

                   $name1  ="sandeep kumar nehra";
                   $name2  ="sandeep'kumar'nehra";
                   $name3  ="sandeep\"kumar\"nehra";
                   $name4  ='sandeep"kumar"nehra';
                   $name5  ='sandeep\'kumar\'nehra';    // (\' escape character)

PHP boolean type

boolean variables can only have two possible values, true or false.

                    $equal     = true;
                    $unequal   = false;

comparisons you make in your scripts always have a boolean outcome.look this script code

                  $y  = (20<=200);      //y hold true value

php Object type

php is a object oriented programming language.

in php we can create new object, use the new operator to instantiate a class.

an object is a data type which stores data and information on how to access that data.

               class  software {
                                  var $version;
                                  var $type;
                   function  software(){  $version=23.2323; $type ="data-base"; }
                   function  dis(){  echo  "version = $version";}
                                  $obj  = new software();        

NULL value in php

the special null value represents a variable with no value.

a variable is considered to be null if:

  • it has been assigned the constant null.
  • it has not been set to any value yet.
               $str = "ram";
               $str = null;