PHP Booleans Data type

A Boolean represents two possible states: TRUE or FALSE. It can be either TRUE or FALSE.  It is often used in conditional testing.

Example :

<?php
$var1 = True; // assign the value TRUE to $foo
var_dump($var1); // function returns the data type and value.
?>

Output :

boolean true

PHP Integers Data type

An integer is a number of the set ℤ = {..., -2, -1, 0, 1, 2, ...}.

Rules for integers:

  • An integer must have at least one digit

  • An integer must not have a decimal point

  • An integer can be either positive or negative

  • Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0)

Example :

<?php
 $var1 = 1234; 		// decimal number
 var_dump($var1);	// function returns the data type and value.
 $var2 = -123; 		// a negative number
 var_dump($var2); 	// function returns the data type and value.
 $var3 = 0123; 			// octal number (equivalent to 83 decimal)
 var_dump($var3); 	// function returns the data type and value.
 $var4 = 0x1A; 			// hexadecimal number (equivalent to 26 decimal)
 var_dump($var4); 	// function returns the data type and value.
?>

Output :

int 1234
int -123
int 83
int 26

PHP Float Data type

Floating point numbers (also known as "floats", "doubles", or "real numbers") are decimal or fractional numbers, like demonstrated in the example below.

Example :

<?php
 $var1 = 5.234;
 var_dump($var1); // function returns the data type and value.

 $var2 = 5.3e5;
 var_dump($var2); // function returns the data type and value.

 $var3 = 4E-8;
 var_dump($var3); // function returns the data type and value.
?>

Output :

float 5.234
float 530000
float 4.0E-8

PHP String

A string is a sequence of characters, where a character is the same as a byte. This means that PHP only supports a 256-character set.

A string always written in single quotes or double quotes .

Example :

<?php 
$var1 = "Jawab Adda";
$var2 = 'Jawab Adda';
var_dump($var1); // function returns the data type and value.
var_dump($var2); // function returns the data type and value.
?>

Output :

string 'Jawab Adda' (length=10)
string 'Jawab Adda' (length=10)

PHP Array

Array is collection of values a single array stores multiple values. An array can be created using the array() language construct

In PHP, there are three types of arrays:

  • Indexed arrays - Arrays with a numeric index

  • Associative arrays - Arrays with named keys

  • Multidimensional arrays - Arrays containing one or more arrays

Example :

<?php 
$lang = array("HTML","PHP","MYSQL");
var_dump($lang);// function returns the data type and value.
?>

Output :

array
  0 => string 'HTML' (length=4)
  1 => string 'PHP' (length=3)
  2 => string 'MYSQL' (length=5)

PHP Object

objects, which can contain variables and  methods (functions)  In PHP, an object must be explicitly declared.

class keyword used to declare class in php A class is a structure that can contain properties and methods.

Example :

<?php 
class Book {
    function Book() {
        $this->name = "PHP Language";
    }
}

$obj = new Book();// create an object
echo $obj->name;// show object properties
var_dump($obj);// function returns the data type and value.
?>

Output :

PHP Language
object(Book)[1]
  public 'name' => string 'PHP Language' (length=12)

PHP Null

Null is a only data type which can have only possible value is NULL this mean it can have only one value : Null

Suppose if we declare a variable without a assign any value then  it is automatically assigned a value of NULL  

A variable is considered to be null if:

  • it has been assigned the constant NULL.
  • it has not been set to any value yet.
  • it has been unset().

Example :

<?php
$var = "Jawab Adda";
$var = null;
var_dump($var);// function returns the data type and value.
?>

Output :

null

PHP Resources

A resource is a special variable, holding a reference to an external resource.

Resource variables typically hold special handlers to opened files and database connections.

Example :

<?php
// Open a file for reading
$handle = fopen("filename.txt", "r");
var_dump($handle);// function returns the data type and value.
?>

Output :

resource(3, stream)