Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

in Table 47.1.


Table 47.1 PHP Variable Types


Type Stores

integerWhole    numbers;    for example,     1 ,     9 ,    or   324809873

float Fractional    numbers;    for example,    1.1,    9.09,   or  3.141592654

string Characters;  for example,    “a”,    “sfdgh”,    or  “Ubuntu
Unleashed”

booleantrue or  false

array Several   variables   of  any type

The first four variables in Table 47.1 can be thought of as simple variables
and the last one as a complex variable. Arrays are simply collections of
variables. You might have an array of numbers (for example, the ages of all
the children in a class); an array of strings (for example, the names of all
Wimbledon tennis champions); or even an array of arrays, known as a
multidimensional array. Arrays are covered in more depth in the next section
because they are unique in the way they are defined.


An object is used to define and manipulate a set of variables that belong to a
unique entity. Each object has its own personal set of variables, as well as
functions that operate on those variables. Objects are commonly used to
model real-world things. You might define an object that represents a TV,
with variables such as $CurrentChannel (probably an integer),
$SupportsHiDef (a Boolean), and so on.


Of all the complex variables, the easiest to grasp are resources. PHP has many
extensions available to it that allow you to connect to databases, manipulate
graphics, or even make calls to Java programs. Because they are all external
systems, they need to have types of data unique to them that PHP cannot
represent using any of the six other data types. So, PHP stores their custom
data types in resources—data types that are meaningless to PHP but can be
used by the external libraries that created them.


Arrays


Arrays are one of our favorite parts of PHP because the syntax is smart and

Free download pdf