Who's Online
We have 7 guests onlineBreadcrumbs
| Data types |
PHP Data Types
A program can do many things, including perform calculations, sort names, prepare phone lists, display images, play chess, ad infinitum. To do anything, however, the program works with the data that is given to it. Data types specify what kind of data, such as numbers and characters, can be stored and manipulated within a program. PHP supports a number of fundamental basic data types, such as integers, floats, and strings. Basic data types are the simplest building blocks of a program. They are called scalars and can be assigned a single literal value such as a number, 5.7, or a string of characters, such as "hello", a date and time, or a boolean (true/false).
There are two numeric values in PHP, they are:
There are three ways to represent the numeric values:
Example: 12345 integer 23.45 float .234E–2 float in scientific notation .234e+3 float in scientific notation 0x456fff integer in base 16, hexadecimal 0x456FFF integer in base 16, hexadecimal 0777 integer in base 8, octal Code example: <html>
An output for this example will be:
String values are sequence of characters, included in a single quote or double quotes, for 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, For example: ‘She wrote: \’PHP is easy to learn\’’. The quote is not the only special character that can be escaped, other characters that can be escaped are: \n Line feed For example: “This is \n a string”
this will evaluate(echo out) to: This is a string
Boolean values are true or false, also 0 and empty string evaluates to false, and any numeric value rather than zero, or a string that is not empty evaluates to true.
An array is a collection of elements of heterogeneous type, arrays will be explained later.
An object is a collection of data and code, you will learn about Objects later in a this tutorial.
NULL means no value. It does not contain any meaningful data.
|