Internet Technology

Unit Five: XML, DTD, XSTL, XHTML

place your ad here

Data Types in PHP || Server Side Scripting || OnlineNotesNepal

Data Types in PHP || Server Side Scripting || OnlineNotesNepal

Data Types in PHP

The values assigned to a PHP variable may be of different data types including simple string and numeric types to more complex data types like arrays and objects.

PHP supports a total of eight primitive data types: Integer, Floating point number or Float, String, Booleans, Array, Object, resource, and NULL. These data types are used to construct variables.

PHP Integers

Integers are whole numbers, without a decimal point (…, -2, -1, 0, 1, 2, …). Integers can be specified in decimal (base 10), hexadecimal (base 16 – prefixed with 0x) or octal (base 8 – prefixed with 0) notation, optionally preceded by a sign (- or +).

PHP Integers

PHP Strings

Strings are sequences of characters, where every character is the same as a byte.

A string can hold letters, numbers, and special characters and it can be as large as up to 2GB (2147483647 bytes maximum). The simplest way to specify a string is to enclose it in single quotes (e.g. ‘Hello world!’), however, you can also use double quotes (“Hello world!”).

PHP Strings

PHP Floating Point Numbers or Doubles

Floating point numbers (also known as “floats”, “doubles”, or “real numbers”) are decimal or fractional numbers,

PHP Floating Points

PHP Booleans

Booleans are like a switch it has only two possible values either 1 (true) or 0 (false).

PHP Booleans

PHP Arrays

An array is formally defined as an indexed collection of data values. Each index (also known as the key) of an array is unique and references a corresponding value.

PHP Arrays

PHP Objects

An object is a data type that not only allows storing data but also information on, how to process that data. An object is a specific instance of a class that serves as templates for objects. Objects are created based on this template via the new keyword.

Every object has properties and methods corresponding to those of its parent class. Every object instance is completely independent, with its own properties and methods, and can thus be manipulated independently of other objects of the same class.

PHP Objects

The data elements stored within an object are referred to as its properties and the information, or code which describes how to process the data is called the methods of the object.

PHP NULL

The special NULL value is used to represent empty variables in PHP. A variable of type NULL is a variable without any data. NULL is the only possible value of type null.

PHP Null

When a variable is created without a value in PHP like $var; it is automatically assigned a value of null. Many novice PHP developers mistakenly considered both $var1 = NULL; and $var2 = “”; are same, but this is not true. Both variables are different — the $var1 has a null value while $var2 indicates no value assigned to it.

If you liked our content Data Types in PHP, then you may also like

Please don’t forget to connect with us through our social media sites. Facebook: Online Notes Nepal, Instagram: @online_notes_nepal, LinkedIn: @onlinenotesnepal, and Twitter:@onlinenotenepal.

advertise here
webtrickshome