Articles → PHP → Data Types In PHP

Data Types In PHP






Purpose





Data Types






  1. Boolean
  2. integer
  3. float
  4. string


  1. array
  2. object


  1. Resource
  2. NULL

Boolean




<?php
    $IsValid = False;
?>



Integer




  1. Decimal
  2. Hexadecimal
  3. Octal
<html><head><title></title></head><body>
	<?php
        $decimal_var = 50;
        $octal_var = 050;
        $hex_var = 0x50;

        echo "$decimal_var\n";
        echo "$octal_var\n";
        echo "$hex_var"

        ?></body></html>






  1. PHP_INT_SIZE – Use to determine the size of the integer
  2. PHP_INT_MAX – Use to determine the maximum value of the integer
<?php
        echo PHP_INT_SIZE;
        echo PHP_INT_MAX;
?>





Float




<?php
    $a = 1.456; 
    $b = 12e1; 
    $c = 7E-10;
?>







String




<html><body>
	<?php
        $double_quote = "Hi";
        $single_quote = ' welcome';
        echo $double_quote, $single_quote;
    ?></body></html>





Array




<html><body>
	<?php 
	        $int_Array = array(1,2,3);
	        $string_Array = array("one","two","three");
	        $float_Array = array(1.1,2.2,3.3);

	        print_r($int_Array);
	        print_r($string_Array);
	        print_r($float_Array);
        ?></body></html>





Object




<?php 

	class MyClass
	{
		public $MyVar = "Test";
	}

	$class = new MyClass;	
?>





Resource





NULL




  1. It has not assigned any value
  2. It has been assigned the constant NULL
  3. It has been unset using an unset() method
<?php
    # Case 1
    $not_assigned;
    # Case 2
    $assigned_null = NULL;
    # Case 3
    $unset_variable = 1;
    unset($unset_variable);
?>





Posted By  -  Karan Gupta
 
Posted On  -  Saturday, May 11, 2013

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250