0% found this document useful (0 votes)
37 views

Phpmysql 04 PHP Data Types

This document discusses PHP data types. PHP is a dynamic, loosely typed language that supports several built-in data types including integers, floats, strings, Booleans, arrays, objects, and NULL. Scalar data types can hold only one value at a time and include integers, floats, strings, and Booleans. Integers can be positive or negative and represented in decimal, hexadecimal, or octal format. Floats represent numbers with decimal points. Strings hold letters, numbers, and special characters within single or double quotes. Booleans represent true or false values.

Uploaded by

Abshir Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Phpmysql 04 PHP Data Types

This document discusses PHP data types. PHP is a dynamic, loosely typed language that supports several built-in data types including integers, floats, strings, Booleans, arrays, objects, and NULL. Scalar data types can hold only one value at a time and include integers, floats, strings, and Booleans. Integers can be positive or negative and represented in decimal, hexadecimal, or octal format. Floats represent numbers with decimal points. Strings hold letters, numbers, and special characters within single or double quotes. Booleans represent true or false values.

Uploaded by

Abshir Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

PHP MYSQL

Lecture 04: PHP Data


Types
 PHP is a dynamic, loosely-typed
programming language that
supports several data types.
 The data type is a fundamental
aspect of a programming Department of Computer
language, defining what kind of Science

data to be stored and Semester 6


manipulated in a variable or Lecturer Yasir A. Mohamed
expression.
Cont..

 In PHP, there are several built-in data types, including


integers, floating-point numbers, strings, Booleans,
arrays, objects, and NULL.

 These data types are used to store and manipulate


different types of data in variables and expressions.
Cont..
 Data types are an essential part of any programming
language, including PHP.
 They define the type of data that can be stored in a
variable. PHP is a dynamic, typed language, which means
that variables do not need to be declared with a specific
data type.
 However, it is still important to understand the various
data types in PHP to avoid unexpected results and ensure
efficient code.
PHP Data Types: Scalar Types
 In PHP, scalar types are those data types that can hold
only one value at a time.
 They are called scalar because they represent a single
value, as different to multiple types, that can store
multiple values.
 PHP has four scalar data types: integers, floating-point
numbers, strings, and Booleans.
 Each of these data types has its subtypes, which we will
explain below.
Cont.
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 at least one digit
 An integer must not have a decimal point
 An integer can be either positive or negative
 Integers can be stated in: decimal (base 10), hexadecimal
(base 16), octal (base 8), or binary (base 2) notation
Integer:

 An integer is a whole number without a decimal point.


 In PHP, integers can be represented in decimal,
hexadecimal, and octal format.

 $num1 = 123;
 $num3 = 0123; // octal integer
Integer:
 Signed integers:
These are integers that can be both positive and negative.
They are represented in PHP using
the 'int' or 'integer' keyword.
 Hexadecimal integers:
These are integers that are represented in base-16. They
are began with '0x' or '0X' and can contain the
digits 0−90−9 and the letters A−F.
Example of PHP Integer
Integer:
 Signed integers:
These are integers that can be both positive and negative.
They are represented in PHP using
the 'int' or 'integer' keyword.
 Hexadecimal integers:
These are integers that are represented in base-16. They
are began with '0x' or '0X' and can contain the
digits 0−90−9 and the letters A−F.
float
 Float (floating point number) is a number with a decimal
point or a number in exponential form.
 In the following example $x is a float.
 In floating point data type rule x variable must store
decimal point number like 0.4567 or 567.78
Example of floating point
number
PHP Boolean
 A Boolean represents two possible states: TRUE or FALSE.
$x = true;
$y = false;

 Booleans are often used in conditional testing. You will


learn more about conditional testing in a later chapter of
this semester.
PHP String
 A string is a non-numeric data type. It holds letters or
any alphabets, numbers, and even special characters.

 String values must be enclosed either within single


quotes or in double quotes. But both are treated
differently. To clarify this, see the example below:
Example of String
PHP String
 A string is a non-numeric data type. It holds letters or
any alphabets, numbers, and even special characters.

 String values must be enclosed either within single


quotes or in double quotes. But both are treated
differently. To clarify this, see the example below:
PHP Boolean
In this slide I will explain Boolean data types in
PHP. Boolean is the simplest type. A Boolean expression is a
true type value. It is used in control structures like for testing
portions of an if statement. It can be either TRUE or FALSE.
Example of Boolean
Thanks!
Any questions?

You can find me at:


[email protected]
[email protected]
www.sunriseacademy.com

You might also like