Articles → PHP → Data Types In PHP
Data Types In PHP
Purpose
Data Types
- Boolean
- integer
- float
- string
- array
- object
- Resource
- NULL
Boolean
<?php
$IsValid = False;
?>
Integer
- Decimal
- Hexadecimal
- 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>
- PHP_INT_SIZE – Use to determine the size of the integer
- 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
- It has not assigned any value
- It has been assigned the constant NULL
- 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);
?>