AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML Tutorial

PHP Data Types


<< Previous Page
PHP Echo and Print
Next Page >>
PHP String Function
In PHP language, unlike other programming languages (C ++, Java, etc.), we do not have to declare the data type, because the PHP language automatically determines the assigned value.

PHP Variables can store data of different types.

PHP language supports the following data types:
Integer
String
Float
Array
Boolean
Object
Resource
NULL


PHP Integer, example


Integer - represents the set of integers Z = {..., -2, -1, 0, 1, 2, ...}. Variables of this type can be initialized with integers specified in decimal (base 10), hexadecimal (base 16) or octal (base 8).

Example:
$ a = 1234; // integer decimal
$ a = -123; // negative integer
$ a = 0123; // integer in octal format - the number must be preceded by a 0
$ a = 0x1AB; // integer in hexadecimal format - the number is preceded by 0x

Example:

<?php
$x = 6867;
echo $x."is ";
var_dump($x);
?>

Note: The PHP statements end with a semicolon (;).

PHP String, example


There are 3 ways to define String variables, but only 2 are commonly used:
- simple quotation marks: $a = 'This is a string';
- double quotes: $a = "This is a string";
To display the apostrophe (') within the text, it must be preceded by the backslash (\) character. The same goes for displaying the backslash (\) character.

Example:
$a = ‘Arnold once said: „I’ll be back”‘;
// Will display: Arnold once said: “I’ll be back”
The difference between the two ways is that in the second case some special characters can be inserted, and if a variable appears within the text, it will be replaced by the value contained in it.

Example:
$x = 40;
$a = "$x participants in the PHP course have registered."; // 40 participants in the PHP course have registered. The special characters that can be used are the following:
n new line (line feed)
r carriage return
t tab
\ backslash
$ the dollar sign
" quotation mark

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

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

$x = 40;
$a = "$x participants in the PHP course have registered.";

echo $a
?>

Boolean

Boolean - is the simplest type of data. A Boolean variable can have only two values: TRUE or FALSE.
It can also take integer values to represent the above, 0 means FALSE, and any other integer value than 0 means TRUE. In the following examples the variable receives the value TRUE (true):
$a = TRUE; $a = 1; $a = -1;
or FALSE (false): $a = FALSE; $a = 0; $a = ""; // empty
<< Previous Page
PHP Echo and Print
Next Page >>
PHP String Function




PHP Data Types - php tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.