Lesson 3 - PHP Datatypes
Lesson 3 - PHP Datatypes
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)
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