Tuesday 7 August 2018

PHP Data Types - PHP training in chandigarh


PHP Data Types


Variables can store data of different types, and different data types can do different things.
PHP supports the following data types:
- String
- Integer
- Float (floating point numbers - also called double)
- Boolean
- Array
- Object
- NULL
- Resource

PHP String


A string is a sequence of characters, like "Hello world!".
A string can be any text inside quotes. You can use single or double quotes:

Example

<?php
$x = "Hello world!";
$y = 'Hello world!';

echo $x;
echo "<br>";
echo $

PHP Training in chandigarh

PHP Integer

An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.
Rules for integers:
  • An integer must have no less than one digit
  • An integer can not have a decimal point
  • An integer can either be negative or positive  
  • Formats in which Integers can be expressed are:
  • Decimal (10-based),
  • Hexadecimal (16-based - prefixed with 0x)
  • Octal (8-based - prefixed with 0)

In the example below, $ x is an integer. The PHP function var_dump () returns the data type and
 the value:
Example
<?php
$x = 5985;
var_dump($x);
?>


PHP Float
A floating point number is a number with a decimal point or a number in exponential form.
In the example below, $ x is a float. The function var_dump () returns data types and values:

Example

<?php
$x = 10.365;
var_dump($x);
?>

PHP Boolean
A boolean represents two possible states: true or false.
$ x = true;
$ y = false;
Boolean is often used in conditional testing.


PHP Array

An array stores multiple values in a single variable.
In the following example, $cars is an array. The function var_dump ()  returns data types and values:

Example

<?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>


PHP Object

An object is a data type,  where data and the information on how to process that data is stored. 
In PHP, an object has to be explicitly declared.
First of all, we have to declare a class of the object. For this, we use class keywords. A class is 
a structure in which the properties and methods can be:

Example

<?php
class Car {
    function Car() {
       $this->model = "VW";
    }
}

// create an object
$herbie = new Car();

// show object properties
echo $herbie->model;
?>

PHP NULL Value

Null is a special data type with only one value: NULL.
A variable NULL of data type is a variable that does not have a value specified.
Tip: If a variable is created without a variable, then it is automatically assigned the value of NULL.
Variables can also be emptied by setting the value to the NULL:

Example

<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>

PHP Resource


The special resource type is not the actual data type. This is the storage of reference to
 external functions and resources of PHP.
A common example of using the resource data type is the database call.
We will not talk about the resource type here, because it is an advanced topic.


For more information join CBitss technologies . CBitss Provides Best PHP Training in chandigarh 
 contact Cbitss Technologies. more information join now ...







0 comments:

Post a Comment