PHP Tutorial

Your cool punch line

PHP Data Types

PHP supports eight primitive types.

Four scalar types:
1). Boolean
2). Integer
3). Float (floating-point number, aka 'Double')
4). String


Two compound types:
1). Array
2). Object


And finally two special types:
1). Resource
2). NULL



Booleans Data Types

This is the easiest type. A boolean expresses a truth value. It can be either TRUE or FALSE.

Syntax:-
To specify a boolean literal, use either the keyword TRUE or FALSE. Both are case insensitive.

<?php
$bool_var = True; // assign the value TRUE to $bool_var
?>
Go Top

Integers Data Types

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

Syntax:-
Integers can be specified in decimal (10-based), hexadecimal (16-based) or octal (8-based) notation, optionally preceded by a sign (- or +).

If you use the octal notation, you must precede the number with a 0 (zero), to use hexadecimal notation precede the number with 0x.

<?php
$int_var = 1234; # decimal number
$_var = -123; # a negative number
$_var = 0123; # octal number (equivalent to 83 decimal)
$_var = 0x1A; # hexadecimal number (equivalent to 26 decimal)
?>
Go Top

Float Data Types

Floating point numbers (AKA "floats", "doubles" or "real numbers") can be specified using any of the following

Syntax:-

<?php
$flot_var = 1.234;
$flot_var = 1.3e4;
$flot_var = 8E-10;
?>
Go Top

String Data Types

String values are sequence of characters, included in a single quote or double quotes,
PHP Example:-‘This is a string’.

The value inside the quotes are not modified, so if you want to use quotes inside the string, then they have to be escaped, we escape characters in PHP by using backslash,
PHP Example:- ‘She wrote: \’PHP is easy to learn\’’.

\n line feed
\r Carriage return
\t Tab
\\ Backslash
\” Double quotes
PHP Example:- “This is \n a string”, this will evaluate to:
This is
a string

Go Top

Array Data Types

An array is a collection of elements of heterogeneous type.

Go TopMore...

Object Data Types

An object is a collection of data and code. To initialize an object, you use the new statement to instantiate the object to a variable.

Syntax:-

<?php
class object_var
{
    function do_object_var()
    {
        echo "Doing object_var.";
    }
}
$bar = new object_var;
$bar->do_object_var();
?>
Go Top

Resource Data Types

A resource is a special variable, holding a reference to an external resource. Resources are created and used by special functions.

Go Top

NULL Data Types

The special NULL value represents that a variable has no value. NULL is the only possible value of type NULL. A variable is considered to be NULL if

Syntax:-
That is the case insensitive keyword NULL.

<?php
$var = NULL;       
?>

PHP Introduction

PHP Basic Development

PHP Control Structures

PHP Functions

PHP Arrays

PHP File System

Working With PHP Forms

PHP Classes And Objects

Introduction To Database

PHP Cookies

PHP Session

Computer SMS


?Computer Science is no more about computers than astronomy is about telescopes.


?Computers must be male. As soon as you commit to one you realize that if you had waited a little longer, you could have obtained a better model. In order to get their attention, you have to turn them on. Big power surges knock them out for the rest of th


More Free SMS


Review w3schoolas.com on alexa.com


© w3schoolas.com . All right reserved.www.w3schoolas.com Sitemap Overall Visits = 316