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

Lesson 3 - PHP Datatypes

This document discusses PHP datatypes and type casting. It covers scalar datatypes like boolean, integer, float and string, as well as compound datatypes like arrays and objects. Examples are given of type casting operators and functions for getting and setting variable types. Predefined type functions are also outlined, including gettype(), settype(), and type identifier functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Lesson 3 - PHP Datatypes

This document discusses PHP datatypes and type casting. It covers scalar datatypes like boolean, integer, float and string, as well as compound datatypes like arrays and objects. Examples are given of type casting operators and functions for getting and setting variable types. Predefined type functions are also outlined, including gettype(), settype(), and type identifier functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Web Architecture, Tools, and

Introduction to PHP

Slide 1
PHP Datatypes

Datatypes
is the generic name assigned to any data sharing a common set of
characteristics.

Scalar Datatypes
Capable of containing a single item of information
(Boolean, Integer, Float (float, double or real numbers), String)

Compound Datatypes
allow for multiple items of the same type to be aggregated under a
single representative entity.
(Array and Objects)

Slide 29
Scalar Datatypes
Eample:

Slide 30
Compound Datatypes

Example:

Output:

Output:

Slide 31
PHP Type Casting Operators

Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.105

Slide 32
PHP Type Casting Operators

Example: Output:

Slide 33
PHP Type Juggling

Example: Output:

Slide 34
Predefined Type Functions
gettype() function
returns the type of the variable. Possible return values are
integer, double, boolean, string, array, object, resource,
unknown types.
prototype:
string gettype(mixed var)

settype() function
converts a given variable to a specific type.
prototype:
boolean settype(mixed var, string type)

Predefined Type Identifier Functions


is_array(), is_bool(), is_float(), is_integer(),
is_null(), is_numeric(), is_object(), is_resource(),
is_scalar(), and is_string()

Slide 35
Type Functions

Example:

Output:

Slide 36
Summary
• PHP was developed originally by Rasmus Lerdorf
• Seev Suraski and Andi Gutsman were the one who contribute most
in PHP development.
• PHP key categories are practicality, power, possibility, and price.
• PHP is a embedded language that is commonly embedded on
HTML
• PHP is a server-side scripting language that runs its application on a
Web server.
• Much of the PHP syntax were derive from C programming
Language.
• You can integrate database easily in PHP.
• Standard PHP script are enclosed by <?php and ?> tags.
• Each statement in PHP must be terminated with a semi-colon(;).
• All variable in PHP must have a dollar ($) character before its
identifier.
Slide 37
An introduction to PHP web programming

Summary (Continue)
• PHP variables are not explicitly declared.
• You can use echo, print, or printf function for outputting strings to internet
browser.
• You can enclosed string using a pair of single quote or pair of double
quote.
• String inside a pair of single quote interpreted as literal except for the
single quote itself.
• String inside a pair of double quote interpreted as literal with some
exception like using dollar character.
• To explicitly display the character on the internet browser use backslash (\)
character like \$, \’, \” and etc.
• Datatypes in PHP can be categorized as scalar or compound datatypes.
• You can explicitly change the type of a variable in PHP.
• PHP support some predefined type function that can be used in
manipulating type variables.

Slide 38

You might also like