Enter your Sign on user name and password.

Forgot password?
Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!

Use Chrome browser to play professor video
Matthew M.

Matthew M.

Miscellaneous Topics

Slide Duration:

Table of Contents

Course Introduction

12m 13s

Intro
0:00
What Is PHP?
0:12
PHP Hypertext Preprocessor
0:13
Why Learn PHP?
1:09
Why Learn PHP?
1:10
Web Application: Educator Store
2:25
Web Application: Educator Store
2:26
Example of Web Application
3:18
PHP in the Educator Store
7:12
Dynamic Content Generation
7:22
Ease of Website Maintenance
7:55
Form Input Processing and Access to Advanced Functionality
9:00
What You Will Learn
9:36
What You Will Learn
9:37
Who Is This Course For?
10:56
Who Is This Course For?
10:57
How PHP & The Web Work

15m 32s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Client-Server Model
0:53
Client-Server Model
0:54
HTTP Protocol
2:15
Definition of Protocol
2:16
Hypertext Transfer Protocol (HTTP)
2:37
Uniform Resource Locators
3:46
Uniform Resource Locators (URLs)
3:47
Form of URLs
4:13
Accessing Webpages with URLs
5:13
Serving Webpages
6:14
Serving Webpages, Client Machine, and Server Machine
6:15
Static vs. Dynamic Webpages
8:30
Static Webpage
8:31
Dynamic Webpage
8:55
Server-Side Scripting
9:54
Server-Side Scripting
9:55
Static and Dynamic Webpage Coding Example
11:17
Static and Dynamic Webpage Coding Example
11:18
Serving Dynamic Webpages
13:07
Serving Dynamic Webpages
13:08
Setting Up Your Development Environment

33m 11s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Development Environments
1:04
Development Environments
1:05
Our Default Development Environment: Window 7
1:54
Remote Development
4:04
Development Machine & Remote Server
4:05
Local Development
6:54
Development Machine
6:55
Software Used In This Course
9:41
Firefox Web Browser & Firebug Add-On
9:42
XAMPP
12:15
PSPAD Text Editor
13:16
XAMPP Installation
13:49
XAMPP Installation
13:50
Verify XAMPP Install
16:26
Verify XAMPP Install
16:27
localhost
19:08
localhost and 127.0.0.1 'loopback' IP Address
19:09
Document Root
21:16
Document Root and Directory Name
21:17
Document Root for Apache in XAMPP: htdocs & Example
22:13
Text Editor Spectrum
26:12
Text Editor Spectrum: Barebones to IDE
26:13
PSPad & Example
27:02
Finding Help
30:26
Web Resources
30:27
Homework Challenge
31:36
Homework Challenge
31:37
Homework Challenge (cont.)
32:38
Homework Challenge (cont.)
32:39
Your First PHP Script

12m 41s

Intro
0:00
Lesson Overview
0:19
Lesson Overview
0:20
.php To HTML
1:00
.php To HTML
1:01
PHP Delimiters
2:20
PHP Delimiters: Opening & Closing PHP Tags
2:21
'Hello, World!' Example
4:34
Echo Statement & PHP Tags
4:35
Adding Second Heading
7:34
Homework Challenge
9:56
Homework Challenge
9:57
Basic PHP Syntax

40m 24s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
PHP Delimiters
0:38
Long and Script Form
0:39
Short and ASP Style
1:33
Example
2:01
php.ini: PHP's Configuration
3:40
php.ini
3:41
Configuration Directives
3:48
Short and ASP Style: Enabled/Disabled
4:13
phpinfo()
7:58
Statements
14:28
PHP Statements
14:29
Example: PHP Statements
14:55
Comments
16:53
PHP Comments
16:55
Single-line Comments
17:37
Multi-line Comments
18:13
Example: PHP Comments
18:47
Coding Conventions
24:26
Coding Conventions
24:27
Example: PHP Coding Conventions
26:19
Homework Challenge #1
33:51
Homework Challenge #1
33:52
Homework Challenge #1 (cont.)
35:41
Homework Challenge #1 (cont.)
35:42
Homework Challenge #2
36:09
Homework Challenge #2
36:10
Homework Challenge #2 (cont.)
38:07
Homework Challenge #2 (cont.)
38:08
Variables & Numeric Data Types

16m 38s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:12
Working With Data
0:48
8 Types of Data for PHP
0:49
Identifiers
1:40
Identifiers: Definition and Example
1:41
Variables
2:47
Variables Definition
2:48
Variables Syntax
3:06
Integer Data Type
4:44
Integer Data Type
4:45
Integer Literals
5:08
Examples
5:30
Float Data Type
6:26
Float Data Type
6:27
Float Literals
7:00
Example
7:21
Example: PHP Code Declaring Variables
8:06
Example: PHP Code Declaring Variables
8:07
var_dump() Function
9:59
var_dump()
10:00
Example: Code and Output
10:30
Example: var_dump() Function
11:19
Coding Conventions: Variables
12:32
Lower Camel Case Notation
12:33
Variable Name Lengths
13:54
Homework Challenge
14:54
Homework Challenge
14:55
String Data Type

18m 6s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
String Data Type
0:29
String Data Type
0:30
Specifying String Literals
1:03
Single-Quoted Strings
1:53
Single-Quoted Strings
1:54
Escape Sequences
2:31
Escape Sequences
2:32
Example
2:46
Escape Sequences for Commonly Used Special Characters
4:32
Double-Quoted Strings
6:04
Double-Quoted Strings
6:05
Variable Interpolation
6:44
Coding Conventions: Strings
7:54
Coding Conventions: Strings
7:55
Homework Challenge
8:54
Homework Challenge
8:55
Include Files & Web Application Introduction

38m 43s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
include Statement
0:47
include Statement: Definition
0:48
Include Statement: Syntax
2:05
include Statement: Example
2:25
include Path
6:32
Absolute and Relative Path
6:34
Specified Path
7:15
Not Specified Path
7:55
Code Reuse
9:35
Code Reuse
9:36
Example
11:11
require Statement
12:56
require Statement: Definition
12:57
require Statement: Syntax
13:32
Include versus Require
13:52
Coding Conventions
16:33
Coding Conventions
16:34
Introduction to Our Web Application
20:32
Introduction to Our Web Application
20:33
Updating Web Application
21:14
Web Application Example
22:59
Homework Challenge
35:33
Homework Challenge
35:34
Homework Challenge (cont.)
37:38
Homework Challenge (cont.)
37:39
Arrays

34m

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is an Array?
0:42
What is an Array?
0:43
Arrays in PHP
1:44
Keys and Values
2:15
Types of Arrays
3:37
Indexed Arrays & Associative Arrays
3:38
array() Construct
6:47
Declaring Arrays
6:48
Defining Indexed Array
7:00
Defining Associative Arrays
7:43
Square Bracket Syntax
8:50
Square Bracket Syntax
8:51
Accessing Indexed Arrays
9:02
Accessing Associative Arrays
9:56
Arrays Example
10:41
Indexed Arrays Example
10:45
Associative Arrays Example
13:55
Multi-Dimensional Arrays
18:28
Multi-Dimensional Arrays
18:29
Multi-Dimensional Arrays Example
18:51
Multi-Dimensional Arrays in PHP File
20:34
Coding Conventions: Arrays
27:59
Coding Conventions: Arrays
28:00
Homework Challenge #1
29:20
Homework Challenge #1
29:21
Homework Challenge #2
30:38
Homework Challenge #2
30:39
Web Application Development

27m 38s

Intro
0:00
Versions
0:14
Version 3.0
1:23
Version 3.1
8:08
Version 3.2
11:42
Version 3.3
20:27
Homework Challenge
26:31
Homework Challenge
26:32
Script Input & The GET Method

30m 18s

Intro
0:00
Lesson Overview
0:15
Lesson Overview
0:16
Providing Input to PHP
0:39
GET Method, POST Method, and Cookies
0:40
Name/Value Pairs
1:22
GET Method
1:57
HTTP GET Method
1:58
Query String
2:52
GET Method Example
3:38
GET Method Example
3:39
Review of HTML Forms
8:16
HTML Forms
8:17
Input Control and Submitted Form
9:13
<form> Tag
10:07
<form> Tag
10:08
Method
10:34
Action
11:13
Input Control Examples
11:50
Input Control Examples
11:51
Common Input Controls
17:31
Common Input Controls
17:32
Query Strings
18:52
Query Strings
18:53
Query Strings Syntax
19:12
URL Encoding
20:01
URL Syntax
20:02
Examples
21:17
Simple Form Example
22:28
urlencode() Function
24:08
urlencode() Function
24:09
Example
25:03
urlEncoding Text Example
25:54
Simple Form Example
25:55
Homework Challenge
28:46
Homework Challenge
28:47
Accessing Form Data in PHP

32m 1s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
$_GET Array
0:48
$_GET Array
0:49
Accessing the Value of a Name/Value Pair Submitted Via GET
1:04
Name Form Example
2:54
Name Form and the $_GET Array
2:55
Using Arrays with Input Controls
6:34
Using Arrays with Input Controls
6:35
Common Example
6:47
Indexed Array Form Example
8:16
Indexed Array Form Example
8:17
Associative Arrays with Input Controls
10:14
Associative Arrays with Input Controls
10:15
Associative Arrays Example
11:41
Associative Arrays Example
11:42
Echo Form Example
15:18
Echo Form Example
15:19
Outputting Arrays In String
23:42
Variable Interpolation
23:43
Outputting a Value in an Indexed Array Within a String
24:12
Simple' Syntax, 'Complex' Syntax, and 'Curly Brace' Syntax
25:00
Outputting Arrays In String Example
26:25
Outputting Arrays In String Example
26:26
Homework Challenge
29:39
Homework Challenge
29:40
Web Application Development

20m 20s

Intro
0:00
Lesson Overview
0:19
Lesson Overview
0:20
Version 3.3
0:38
Version 3.3
0:42
Version 4.0 Changelog
2:43
GET Query
2:45
Adding, Editing, and Removing
3:24
Version 4.0 Coding Example
3:55
item.php, itemID, and itemListing
4:00
Version 4.1 Changelog
10:36
Version 4.1 Changelog
10:37
Version 4.1 Coding Example
11:45
Adding Checkout and Thank You & Editing Footer and Store
11:46
Homework Challenge
18:45
Homework Challenge
18:46
Expression & Operators

31m 56s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Expressions
0:41
Expressions Definition
0:42
Example: Literals
0:55
Example: Variables
1:05
Operators
1:44
Operators Definition
1:45
Unary, Binary, and Ternary Operators
2:07
Assignment Operators
2:52
Assignment Operators
2:53
Array Assignment Operator
3:47
Arithmetic Operators
6:15
Operators for Common Arithmetic Operations
6:16
Modulus Operator
7:41
Arithmetic Operators Example
8:25
Increment/Decrement Operators
10:48
Increment/Decrement Operators
10:49
Pre- and Post- Increment/Decrement
12:43
Coding Example
15:14
Combined Assignment Operators
16:44
Combined Assignment Operators
16:45
Combined Assignment Operators Examples
18:23
Coding Example
19:39
String Operators
20:28
Concatenation Operator, String Variables, and String Literals
20:29
String Operators Example
22:41
Precedence & Associativity
23:40
Precedence & Associativity
23:41
Expression Containing Multiple Operations
23:58
Expression Containing Two Operations of Equal Precedence
25:55
Using Parentheses to Force Precedence
26:52
Precedence & Associativity Review
28:57
Homework Challenge
31:08
Homework Challenge
31:09
Web Application Development

20m 51s

Intro
0:00
Lesson Overview
0:15
Lesson Overview
0:16
Version 4.1 Review
0:33
Version 4.1 Review
0:34
Version 5.0 Changelog
1:05
Version 5.0 Changelog
1:06
Version 5.0 Example
2:19
Adding View Cart & Editing Checkout, Footer and Store
2:20
Version 5.1 Changelog
15:36
Version 5.1 Changelog
15:37
Version 5.1 Coding Example
17:33
Forwarding Order Total to Thank You Page
17:34
Homework Challenge
20:09
Homework Challenge
20:10
Boolean & Null Data Types

20m 11s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Boolean Data Type
0:38
Boolean Data Type
0:39
Two Boolean Literals
1:24
Boolean Example
1:50
Boolean Example
1:51
Comparison Operators
4:00
Comparison Operators Definition
4:01
Common Comparison Operators
4:40
Comparison Operators Example
6:49
Comparison Operators (Cont.)
10:10
Identical and Not Identical
10:11
Example: Identical and Not Identical
11:24
Null Data Type
13:36
Null Data Type Definition
13:37
Null Literal
14:08
Variable and Null Data Type
14:30
'==' Operator
15:24
Null Data Type Example
15:59
Coding Convention
18:41
Coding Convention
18:42
Homework Challenge
19:17
Homework Challenge
19:18
Type Casting

22m 41s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Type Juggling
0:54
Type Juggling
0:55
Automatic Conversion
2:23
Type Casting
3:53
Type Casting
3:54
Implicit and Explicit Type Casting
4:00
Explicitly 'cast' a Variable Example
4:16
Type Casting (cont.)
6:48
PHP Allows the Following Explicit Type Casts
6:49
The settype () Function
8:18
Type Casting Coding Example
9:00
Explicit Type Casts
9:01
String Conversions
14:52
String Conversions
15:05
Common Conversions to String
15:55
Numeric Conversions
18:18
Numeric Conversions
18:19
Boolean Conversions
20:29
Boolean Conversions
20:30
Homework Challenge
21:38
Homework Challenge
21:39
Introduction to Functions

52m 20s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
What are Functions?
0:51
Definition of Faction
0:52
PHP and Function Call
1:53
Function Calls
2:42
Function Calls
2:43
Function Arguments
3:17
Return Values
4:56
Return Values
4:57
Function Chaining
6:29
Function Chaining
6:30
PHP.net Function Reference
8:23
PHP.net & Function Prototypes
8:24
PHP.net Function Reference Example
9:29
Optional Function Arguments
12:28
Optional Function Arguments
12:29
String Functions
14:57
strtoupper() and strtolower()
14:58
implode (), str_replace(), explode(), strpos(), substr(), and strlen()
18:31
Array Functions
25:48
count()
25:49
in_array() and array_key_exists()
26:06
sort() and ksort()
26:37
Example: count() and in_array()
27:50
Example: array_key_exists()
29:53
Example: sort() and ksort()
31:20
Date & Time Functions
33:38
date() and time()
33:39
getdate()
34:49
mktime()
35:01
Date & Time Functions
35:12
Example: date() and time()
35:58
Example: getdate()
42:15
Example: mktime()
43:15
Homework Challenge #1
44:31
Homework Challenge #1
44:32
Homework Challenge #1 (Cont.)
45:28
Homework Challenge #1 (Cont.)
45:29
Homework Challenge #2
46:34
Homework Challenge #2
46:34
Homework Challenge #2 (Cont.)
48:06
Homework Challenge #2 (Cont.)
48:07
Homework Challenge #2 (Cont.)
49:17
Homework Challenge #2 (Cont.)
49:18
Homework Challenge #3
50:08
Homework Challenge #3
50:09
Constants

19m 24s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Constants vs. Variables
0:55
Constants vs. Variables
0:56
Constant Identifiers
2:28
Constant Identifiers Definition and Examples
2:29
Declaring Constants
3:47
Two Ways of Declaring Constants
3:48
Syntaxes
4:10
Major Difference in the Two Forms
4:48
Using Constants Example
6:25
Using Constants Example
6:26
Coding Conventions
11:08
Constant Names
11:09
define () Function
11:42
Meaningful Names
12:00
$_SERVER Superglobal
12:23
$_SERVER
12:24
$_SERVER ['DOCUMENT_ROOT']
13:15
$_SERVER Superglobal Example
13:52
Homework Challenge
17:40
Homework Challenge
17:41
Web Application Development

26m 29s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 6.0
1:13
Version 6.0 & Version 5.1 Review
1:14
Version 6.0 Changelog
11:24
Version 6.0 Changelog
11:25
Version 6.1 Changelog
12:00
Version 6.1 Changelog
12:01
Version 6.1 Coding Example
12:42
Version 6.1 Coding Example
12:43
Version 6.2 Changelog
15:18
Version 6.2 Changelog
15:19
Version 6.2 Coding Example
18:19
Version 6.2 Coding Example
18:20
Homework Challenge
25:24
Homework Challenge
25:25
Conditional Control Structures

18m 58s

Intro
0:00
Lesson Overview
0:26
Lesson Overview
0:27
Statement Groups
0:57
Statement Groups
0:58
Example
1:10
Conditional Control Structures
1:38
Conditional Control Structures
1:39
PHP Control Structures
1:56
if Statement
2:32
if Statement
2:33
if Statement (cont.)
3:49
if Statement Coding Example
3:50
else Statement
7:26
else Statement
7:27
if/else Statement Coding Example
8:50
isset() Construct
9:59
isset() Construct
10:00
isset() Construct Coding Example
12:00
Coding Conventions
15:13
Coding Conventions
15:14
Coding Conventions (Cont.)
16:39
Coding Conventions (Cont.)
16:40
Homework Challenge
17:25
Homework Challenge
17:26
Error Handling

19m 8s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Error Handling in PHP
0:41
Error Handling in PHP
0:42
Coding Example
1:45
error_reporting() Function
7:02
error_reporting() Function
7:03
Coding Example
8:04
Additional Error Directives
9:02
display_errors
9:13
log_errors
9:37
error_log
9:50
track_errors
10:12
Coding Examples
10:29
Error Control Operator
13:38
Error Control Operator & Coding Example
13:39
Homework Challenge
16:19
Homework Challenge
16:20
Homework Challenge (cont.)
17:58
Homework Challenge (cont.)
17:59
Logical & Ternary Operators

23m 22s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
Logical Operators
0:49
Logical Operators Definition
0:50
NOT (!)
1:08
OR ( ||, or)
1:35
AND (&&, and)
2:08
XOR (xor)
2:30
Logical Operators (cont.)
2:54
The OR and AND Logical Operators
2:55
Precedence of Logical Operators
3:35
Logical Operators Coding Example
3:58
Logical Operators Coding Example
3:59
Short-Circuit Operators
9:54
Short-Circuit Operators
9:55
Coding Example
10:49
Ternary Operator
14:07
Ternary Operator
14:08
Syntax and Example
14:24
Coding Conventions
17:36
Coding Conventions
17:37
Homework Challenge
19:08
Homework Challenge
19:09
Homework Challenge (cont.)
20:26
Homework Challenge (cont.)
20:27
Web Application Development

19m 27s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 6.2 Review
0:26
Version 6.2 Review
0:27
Version 7.0 Changelog
2:39
Version 7.0 Changelog
2:40
Version 7.0 Coding Example
4:35
Version 7.0 Coding Example
4:36
Version 7.1 Changelog
12:43
Version 7.1 Changelog
12:44
Version 7.1 Coding Example
13:52
Version 7.1 Coding Example
13:53
Homework Challenge
17:42
Homework Challenge
17:43
More Conditional Control Structure

20m 49s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
elseif Statement
0:45
elseif Statement
0:46
elseif Statement Coding Example
1:22
Multiple elseif Statements
2:16
Multiple elseif Statements
2:17
Multiple elseif Statements Coding Example
3:07
Adding an else Statement
5:44
Adding an else Statement Overview
5:45
Adding an else Statement Coding Example
6:50
switch() Statement
8:07
switch() Statement
8:08
switch() Statement (Cont.)
9:14
switch() Statement (Cont.)
9:15
switch() Statement Coding Example
11:09
default Case
14:20
default Case
14:21
default Case Coding Example
15:13
Coding Conventions
15:57
Coding Conventions
15:58
Coding Conventions (cont.)
17:10
Coding Conventions (cont.)
17:11
Homework Challenge
18:06
Homework Challenge
18:07
Homework Challenge (cont.)
19:18
Homework Challenge (cont.)
19:19
Nested Conditional Control Structures

24m 49s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Nested Control Structures
0:36
Nested Control Structures
0:37
Nested Control Structures Coding Example
2:08
Coding Conventions
6:34
Nested vs. Not Nested Control Structures
6:35
Debugging Control Structures
7:51
Debugging Control Structures
7:52
Incorrectly Specified Test Conditions and Forgetting a Break Statement
8:32
Incorrectly Placing an Opening or Closing Curly Brace
12:14
Debugging Tips
16:24
Tracing the Execution of Your Code
16:25
Adding Echo Statement
17:15
Homework Challenge
21:41
Homework Challenge
21:42
Homework Challenge (cont.)
23:08
Homework Challenge (cont.)
23:09
Web Application Development

28m 20s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 7.1 Review
0:46
Version 7.1 Review
0:47
empty () Construct
1:38
empty () Construct
1:39
empty () Construct Coding Example
2:37
Version 8.0
5:32
Version 8.0 Overview
5:33
Version 8.0 Coding Example
7:08
Version 8.0 Coding Example
7:09
Version 8.1
16:13
Version 8.1 Overview
16:14
Version 8.1 Coding Example
19:48
Version 8.1 Coding Example
19:49
Homework Challenge
26:19
Homework Challenge
26:20
Sending Email Using PHP

43m 50s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
Built-in Mail Extension
1:28
Built-in Mail Extension
1:29
SMTP Overview
2:04
SMTP Overview
2:05
SMTP - Windows
3:08
SMTP - Windows
3:09
SMTP - Linux/UNIX
4:58
SMTP - Linux/UNIX
4:59
Mail Configuration Directives
6:35
Mail Configuration Directives
6:36
Coding Example
7:48
Mail Server Authentication
10:20
Mail Server Authentication
10:21
fake sendmail Program
12:27
fake sendmail for Windows
12:28
Main 'add-on' feature
13:03
Username & Password
13:25
SMTP - XAMPP for Windows
14:07
SMTP - XAMPP for Windows
14:08
Sendmail Example
16:19
Sendmail Example
16:20
mail() Function
18:39
mail() Function
18:40
additional_headers
19:45
'From' Header
20:12
mail() Function Coding Example
21:09
mail() Function Coding Example
21:40
Web Application Development
31:43
Version 9.0 Changelog
31:44
ContactUs.php
32:52
ContactUs.php
32:53
contactInfo
33:45
Version 9.0 Coding Example
34:31
Version 9.0 Coding Example
34:32
Homework Challenge
41:32
Homework Challenge
41:33
User-Defined Functions

56m

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Defining Functions
1:29
Four Parts of Defining a Function
1:30
Functions Example 1
2:29
Function Parameters
5:29
Function Parameters
5:30
Functions Example 2
8:20
Return Statements
12:53
Return Statements
12:54
Functions Example 3
14:20
Where to Define Functions
20:34
Where to Define Functions
20:35
include_once Construct
22:10
include_once Construct
22:11
include_once Coding Example
23:55
Reasons to Use Functions
27:44
Take Advantage of Code Reuse
27:45
Improve Code Readability
29:56
Use Instead of 'content' Include Files
32:12
Web Application Development
34:42
Version 10.0 Changelog
34:43
Version 10.0 Coding Example
37:55
Version 10.0 Coding Example
37:56
Outputting HTML in Functions
47:04
Outputting HTML in Functions
47:05
Example
49:02
Coding Conventions
53:16
Coding Conventions
53:17
Homework Challenge
54:33
Homework Challenge
54:34
Variable Scope

31m 37s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is Variable Scope?
0:57
Variable Scope
0:58
Global Scope
1:15
Local Function Scope
1:50
Variable Scope Coding Example
2:26
Variable Scope Coding Example
2:27
global Keyword
8:52
global Keyword Overview
8:53
global Keyword Example
9:25
Superglobals
12:34
Superglobals
12:35
Superglobals Example
14:53
Pitfalls of Global Variables
18:34
Pitfalls of Global Variables
18:35
When to Define Variables
22:09
When to Define Variables
22:10
Putting It All Together
22:56
Putting It All Together Example
22:57
Function Scope
28:56
Function Scope
28:57
Homework Challenge
29:41
Homework Challenge
29:42
Homework Challenge (cont.)
30:59
Homework Challenge (cont.)
31:00
Web Application Development

28m 27s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 11.0 Changelog
0:56
Version 11.0 Changelog
0:57
processGetVar()
1:42
processGetVar() Overview
1:43
processGetVar() Example
2:25
emailComments()
6:35
emailComments() Overview
6:36
emailComments() Example
7:14
outputItemLink()
11:19
outputItemLink() Overview
11:20
outputItemLink() Example
11:45
calcCartTotal()
19:25
calcCartTotal() Overview
19:26
calcCartTotal() Example
21:14
Homework Challenge
25:56
Homework Challenge
25:57
Optional Parameters

19m 35s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Optional Parameters
0:26
Optional Parameters Definition
0:27
Default Values
0:53
Optional Parameters Coding Example
3:26
More on Optional Parameters
6:55
Multiple Optional Parameters
6:56
Coding Example
8:05
Homework Challenge
16:18
Homework Challenge
16:19
Web Application Development

23m 7s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 12.0 Changelog
0:55
Version 12.0 Changelog
0:56
Update to outputLink()
1:44
Update to outputLink()
1:45
outputLink() Coding Example
2:40
outputImg()
13:57
outputImg() Overview
13:58
outputImg() Coding Example
15:35
Homework Challenge
22:05
Homework Challenge
22:06
Introduction to Conditional Loops

57m 20s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
while Loop
0:48
Definition
0:49
Syntax and Usage
1:12
Coding Example
3:33
Looping Over Arrays
13:16
Looping Over Arrays
13:17
Coding Example
13:53
Looping Over Arrays (cont.)
16:43
Internal Array Pointer
16:44
Array Traversal Functions
17:29
current ()
17:30
next () and prev ()
18:16
reset () and end ()
19:25
key ()
19:40
Indexed Arrays: Using current () and next ()
20:40
Indexed Arrays: Using current () and next ()
20:41
Associative Arrays: Using key (), current (), and next ()
24:06
Associative Arrays: Using key (), current (), and next ()
24:07
Array Traversal Functions (cont.)
29:41
list () Construct and Example
30:07
each () Construct and Example
34:40
Lopping Over Arrays Using list(), each()
42:13
Lopping Over Arrays Using list(), each()
42:14
Control Structure Scope
50:37
Definition and Example
50:38
Control Structure Scope Coding Example
51:59
Coding Conventions
54:20
Coding Conventions
54:21
Homework Challenge
54:58
Homework Challenge
54:49
More on Conditional Loops

35m 50s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
do-while Loop
0:42
do-while Loop
0:43
Simple do-while Loop Example
1:51
Another do-while Loop Example
4:09
continue Statement
10:46
continue Statement
10:47
For Example
11:07
continue Statement Coding Example
12:44
break Statement Re-Visited
18:10
break Statement Re-Visited
18:11
break Statement In while Loops Example
19:38
Infinite Loops
23:26
Infinite Loops
23:27
Coding Example
24:57
Common Loop Pitfalls
25:59
Counter Initialization Occurs in Loop
26:30
Counter Not Incremented in Loop
29:30
Unreachable Break Statement
30:50
Coding Conventions
33:48
Do-while Statements Coding Conventions
33:49
Homework Challenge
34:28
Homework Challenge
34:29
Web Application Development

22m 7s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Version 13.0 Changelog
0:48
Updating 'viewCart.php' and calcCartTotal()
0:49
Creating isValidCart()
9:22
Adding Three New Item to the Store & Links
15:56
Version 13.1 Changelog
17:20
Updating outputItemLink() to Remove Its Global Dependency on $itemCatalog
17:21
Homework Challenge
20:34
Homework Challenge
20:35
For & Foreach Loops

29m 28s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
for Loops
0:45
for Loops
0:46
Expression 1
1:22
Expression 2
1:47
Expression 3
2:01
Simple Example
2:27
Simple Example
2:28
Notes on for Loops
8:56
Notes on for Loops
8:57
Ending Loop Using Test Condition and Break Statement
10:06
Ending Loop Using Test Condition and Break Statement
10:07
foreach Loops
12:03
foreach Loops
12:04
Indexed Array Syntax
14:10
Syntax
14:11
Example
15:23
Associative Array Syntax
18:31
Syntax
18:32
Example
19:47
Coding Conventions
25:05
for Loops
25:06
foreach Loops
25:58
Homework Challenge
26:52
Homework Challenge
26:53
Web Application Development

25m 58s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 14.0 Changelog
1:19
Version 14.0 Changelog
1:20
Version 14.0 Coding Example
1:57
Version 14.0 Coding Example
1:59
Version 14.1 Changelog
5:39
Version 14.1 Changelog
5:40
Version 14.1 Coding Example
7:06
Version 14.1 Coding Example
7:07
Version 14.2 Changelog
15:37
Version 14.2 Changelog
15:38
Version 14.2 Coding Example
16:25
Version 14.2 Coding Example
16:26
Homework Challenge
23:35
Homework Challenge
23:36
Conditional Loop Wrap-Up

23m 12s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Nested Conditional Loops
0:39
Nested Conditional Loops
0:40
Coding Example
1:10
continue & break Re-Visited
5:17
Continue Statements and Coding Example
5:30
Break Statements and Coding Example
11:34
Loop Debugging Tips
15:16
Add Short Debug Statement At the Very Beginning
15:17
Output a Counter Variable
18:10
Add Debug Statement At the Very End
19:20
Homework Challenge
20:20
Homework Challenge
20:21
Homework Challenge (cont.)
22:00
Homework Challenge (cont.)
22:01
Variable-Length Parameter Lists

22m 16s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Variable-Length Parameter Lists
0:34
Variable-Length Parameter Lists
0:35
Coding Example
1:51
Variable-Length Parameter Lists (cont.)
5:21
When a Parameter List is Defined For the Functions
5:22
Coding Example
6:32
Variable Type Functions
9:54
is_int (), is_float (), is_string (), and is_bool()
9:55
is_ array ()
10:50
is_null ()
11:01
Variable Type Functions Coding Example 1
11:27
is_numeric() and Example
15:57
Variable Type Functions Coding Example 2
17:12
Homework Challenge
19:35
Homework Challenge
19:36
Homework Challenge (cont.)
20:52
Homework Challenge (cont.)
20:53
Web Application Development

38m 36s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Version 15.0 Changelog
0:33
outputLink (), outputImg (), is_array () and is_string ()
0:34
Version 15.0 Coding Example
1:31
Version 15.0 Coding Example
1:32
Version 15.1 Changelog
7:55
Removing Redundant Code and Adding New Function Called outputHtmlTag ()
7:56
Version 15.1 Coding Example
8:37
Version 15.1 Coding Example
8:38
Version 16.0 Changelog
14:55
Creating emailOrder() Using New Constants ORDER_EMAIL_FROM and ORDER_EMAIL_SUBJECT
14:56
Version 16.0 Coding Example
16:30
Version 16.0 Coding Example
16:31
Version 16.1 Changelog
32:21
Creating formatAsDollars ()
32:22
Version 16.1 Coding Example
32:57
Version 16.1 Coding Example
32:58
Homework Challenge
36:27
Homework Challenge
36:28
Miscellaneous Topics

31m 49s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
register_globals Directive
0:58
register_globals
0:59
Coding Example
2:04
$_GET vs. $HTTP_GET_VARS
4:07
$_GET vs. $HTTP_GET_VARS
4:08
register_long_arrays Directive Coding Example
5:44
Magic Constants
7:30
Magic Constants
7:31
__LINE__, __FILE__, __FIR__, and __FUNCTION__
8:16
Coding Example
9:06
exist() & die()
13:19
exist() & die()
13:20
Coding Example
14:08
Execution Operator
16:23
Execution Operator
16:24
Coding Example
17:27
Array Operators
18:23
Equality (==) and Inequality (!=, <>)
18:43
Identity (===) and Non-Identity (!==)
19:13
Union (+) Operator
19:41
Array Operators Coding Example
20:07
Variable Variables
24:13
Variable Variables
24:14
Coding Example
26:07
Variable Functions
28:02
Variable Functions
28:03
Coding Example
29:13
Loading...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Introduction to PHP
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Transcription

  • Related Services

Lecture Comments (2)

0 answers

Post by Steven Morrison on December 23, 2013

Good course, I enjoyed it! :)

0 answers

Post by David Perry on September 7, 2012

Excellent course. Both the Advanced and this one excellently done. Thank you!

David Perry
Perry Computer Services (Ontario, Canada)
Owner
1-877-737-7927
www.perrycs.com

Miscellaneous Topics

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Lesson Overview 0:10
    • Lesson Overview
  • register_globals Directive 0:58
    • register_globals
    • Coding Example
  • $_GET vs. $HTTP_GET_VARS 4:07
    • $_GET vs. $HTTP_GET_VARS
    • register_long_arrays Directive Coding Example
  • Magic Constants 7:30
    • Magic Constants
    • __LINE__, __FILE__, __FIR__, and __FUNCTION__
    • Coding Example
  • exist() & die() 13:19
    • exist() & die()
    • Coding Example
  • Execution Operator 16:23
    • Execution Operator
    • Coding Example
  • Array Operators 18:23
    • Equality (==) and Inequality (!=, <>)
    • Identity (===) and Non-Identity (!==)
    • Union (+) Operator
    • Array Operators Coding Example
  • Variable Variables 24:13
    • Variable Variables
    • Coding Example
  • Variable Functions 28:02
    • Variable Functions
    • Coding Example

Transcription: Miscellaneous Topics

Hello again, and welcome back to Educator.com.0000

Today's lesson is going to be the last lesson in our Introduction to PHP course.0003

We are going to be covering a variety of miscellaneous topics.0007

We are going to be talking about what is known as the register_globals directive,0013

which is something that you might hear about in talking with other PHP developers and seeing other PHP scripts.0017

We are also going to talk about the difference between the _GET array and the HTTP_GET_VARS array, which we will talk more about in a second.0024

We are going to learn about what magic constants are and discuss the exit and die constructs in PHP.0033

We are going to go over a few new operators that aren't used very often--the execution operator and some array operators.0042

And then, we are going to talk about two sort of advanced topics: what are known as variable variables and variable functions.0049

So, the first thing that we are going to talk about is the register_globals directive.0059

And what it is: it's a directive in php.ini that, when set to on, is automatically going to create global variables for various data0064

that is provided to PHP scripts, like GET inputs.0075

For example, when we had the GET variable that was called name, the way we have accessed it in our scripts is using the _GET array,0079

specifying name as the key to that array.0087

However, if we have the register_globals directive set to on, PHP automatically creates a variable with global scope called name0091

that contains the value of the GET variable name.0100

And so, we could use that variable, name, instead, to access the value supplied along with the name GET variable.0104

This use has been deprecated in PHP as of version 5.3, and this has been done for security reasons.0111

But you may still see code out there that uses that, that doesn't use the _GET array to access GET data.0119

So, I just want to show you what that looks like.0124

If we look at this file, registerGlobals.php, we can see that this is a script that accepts one GET variable called name.0128

And we try to echo that variable using the _GET superglobal array.0138

And then, we also try to do it just using the variable name.0145

And if register_globals is turned on, then we can use this variable name to access that GET variable.0149

The default for the XAMPP installation is to have register_globals turn off.0156

So, if we go ahead and look at register_globals.php, the first thing we are going to see is: we are going to get an error0160

that is going to say "an undefined index and an undefined variable name."0170

The reason it says "undefined index" is because we haven't provided the GET variable called name.0174

So, if we provide name and set it equal to Matthew, we are going to see that _GET ['name']=Matthew.0178

But then, it is going to say that there is an undefined variable name, and it is not going to have a value to output.0185

And if we go and look back at the script, we can see that this is where we tried to output the value of the variable name,0190

that, if register_globals was on, would output the value of the GET variable name.0196

Let's go ahead to php.ini, and I am going to turn on the register_globals directive, which is, again,0202

a deprecated functionality that is turned off by default now, for security reasons.0209

If we go ahead and restart the Apache web server, and we reload the page, we can see now that PHP knows what the variable name is.0214

It has been defined in the global scope, because register_globals was turned on, and we are able to access the value of the GET variable, Matthew.0224

And just to show you that it actually does that, if I change the name to Joe and submit the form,0231

we can see that both _GET with the name key outputs the value Joe, and the variable name has the value Joe.0237

Sort of a similar thing that is related--it is a deprecated feature of PHP--is that, as of version 4.1, the _GET superglobal0249

that we have been using to access GET data was introduced.0259

Prior to that point, PHP programmers typically accessed GET data using a global predefined variable0263

that was an associative array; and it was called HTTP_GET_VARS.0271

And you would access GET data the same way that you would with the GET variable.0277

For example, you would provide, as a key to the array, the name of the GET variable you were interested in.0280

As of version 5.3.0, however, this HTTP_GET_VARS global predefined variable has been deprecated for performance reasons.0287

But you will still see some code out there that uses it, and you can actually enable this HTTP_GET_VARS array,0299

using a configuration directive in php.ini called register_long_arrays.0306

And what that does is determines whether this long array is available.0311

One thing to note is that, even if that directive is turned on, HTTP_GET_VARS is not a superglobal variable, even though it is a global predefined variable.0316

And it is actually different from the GET superglobal; so the data that is contained in that is not the same as the data contained in the _GET superglobal.0327

But I do want to mention this, because you may see this in some older legacy code,0336

where people previously used the HTTP_GET_VARS array to access GET data.0339

So, if we go and take a look at a file called registerLongArrays.php, again, it is a script that takes in one GET variable called name.0345

And here, you can see, we try to output that GET variable using the _GET superglobal, which we have been using in the course.0353

And then, we try to do the same thing using this long array called HTTP_GET_VARS, which we just discussed.0360

Now, if register_long_arrays directive is turned to off, which it is by default now, this second line is not going to work, and the first line should.0368

So, if you go and view the script, the first time we run it, we are going to get two errors,0376

because the _GET superglobal can't access the variable name, because we haven't provided it.0384

So, if we provide a query string that says name equals Matthew, and we hit Enter, we will see that access to the variable using the _GET array worked.0392

It output the name Matthew, which was supplied in the script.0402

But PHP is complaining, saying it doesn't know this variable HTTP_GET_VARS.0405

So, if we go to php.ini (let's turn globals back off), and we turn long arrays on, and go ahead and restart our XAMPP and Apache server,0410

when we reload the page, we should be able to access that variable; and as you can see, we have accessed the GET variable0424

both using the _GET array, and also the HTTP_GET_VARS array.0430

And again, just to show you that that works, we change the name to John, for example.0435

We can see that both of these associative arrays are able to access that GET data.0438

And so, this, again, is a topic that is covered for legacy reasons.0446

I also want to talk about magic constants.0452

And PHP provides a ton of predefined constants available for use in your scripts.0454

We have come across some of those constants when we talked about error reporting, such as E_ALL or E_NOTICE, that defined error reporting levels.0459

Of all the predefined constants PHP has, seven of them are known as magic constants.0468

And they are called magic constants because the values of the constants vary, depending on where they are in a script.0475

So, in a way, they are like constants, in that they are accessed in uppercase notation.0482

They are always available, but their values actually do vary.0487

Out of the seven that are available, the ones that are applicable to the material we have covered so far are these four.0493

There is one called __LINE__, and the way magic variables are named is: they start with two underscores,0499

then the capitalized version of whatever the constant name is, followed by two more underscores.0505

So, __LINE__: if you use that constant in your script, it is going to output the current line number of the script that is currently being executed.0512

If we had the magic constant __FILE__ with the two underscores before and the two underscores after,0523

and we reference that in our script, it is going to provide the absolute path to the script being executed.0527

Likewise, we have the __DIR__ magic constant, which is going to output the absolute directory of the script being executed.0532

And then, there is also the __FUNCTION__ magic constant that outputs the name of a function that is currently being executed.0539

Let's take a look at a file called magicConstants.php.0547

And in the output section, we have an echo statement that says we are outputting the magic constants from the main script.0552

And here, we just have output the __LINE__, __FILE__, __DIR__, and __FUNCTION__ magic constants from within our main script file.0560

Now, what we also have is an include file, because these values change, depending on what file they are in.0569

For example, __FILE__ and __DIR__ and __LINE__ all depend on the file that they are evaluated in.0575

So, an include file that references __LINE__ might have a different line number than if we use __LINE__, for example, right here0585

in the main script, because it is going to be in a different line number in that include file.0592

So, we have a file called magicInclude.php, which, if we look at it, is just a PHP file that outputs all of the four magic constants we learned about.0596

And as we are going to see, it outputs different values, because these values are for the currently-executed file.0604

And for include files, __FILE__ and __DIR__ are going to be different, because they give the file name and directory name0610

of the include file, as opposed to the script file, magicConstants.php, when we reference them here.0617

Additionally, we are also going to create a function called magic, and we are going to output the values of all these same magic constants, as well.0626

And __DIR__ and __FILE__ should be the same, because we have defined this function within the magicConstants.php file.0636

However, we are going to get a value for __FUNCTION__, because now we are within a function, so it is going to output the name magic.0644

And __LINE__ is going to be different, because it is going to output the line where this constant is referenced, which, in this case, is line 17.0649

If we go and load this file in our web browser, we can see a couple of things.0657

We can see, within the body of the main script, that the first reference to line is equal to 29.0667

The __FILE__ magic constant lists the absolute path to the magicConstants.php file on our local machine.0674

It also lists a directory of that file.0685

And then, when we try to output __FUNCTION__, the magic constant outputs nothing, because it wasn't output within a function.0687

So, if we go back and look at the main script, we can see that on line 290695

is where we have used this magic constant, the __LINE__ constant, which is why we get 29.0700

Now, when we go to the include file, you will notice that the absolute file name changed: it changed from magicConstants.php to magicInclude.php.0708

Now, the directories are the same, because both the include file and magicConstants.php are stored in the same directory of our web tree.0718

You also notice that __FUNCTION__ has no value output, because we are not within a function.0727

And the line number is different because, if we look back at magicInclude.php,0732

we can see that, in the include file, the __LINE__ constant is referenced on line 3; therefore, it outputs line 3.0737

The other thing is that, within the function--when we are in the magic function, and we output __LINE__,0745

we are going to get line 17 output, because that is where this line constant is referenced.0753

We are going to get the same __FILE__ and __DIR__ values as we did in the main script, because this function is defined in the same file.0757

But we are going to get a value now, when we try to output __FUNCTION__, because we are in the magic function.0766

And the value of the magic constant __FUNCTION__ is just the name of the currently executing function.0772

So, magic is going to be output.0780

So, when we go and look at the output, we can see that __LINE__ equals 17; __FILE__ and __DIR__ are the same as for magicConstants.php.0782

But we now get a value for this __FUNCTION__ magic constant: in this case, it outputs the name of the function, which is called magic.0790

Now, we are going to talk about what are known as the exit and die constructs in PHP, which is something you might see in PHP code out there.0800

And what they are is functions that are used to terminate the execution of a script--for example, if an error occurs.0808

The exit construct and die construct do the exact same thing: they halt the execution of this script.0816

And they have two options that you can use: one option is: you can provide a status string within the parentheses of the construct.0822

that will get output to the user before the script is terminated.0830

The other option you can do is: you can provide an integer in between the parentheses, which represents an error code0833

that gets passed on to the PHP Interpreter, so the PHP Interpreter can understand0839

if the application ended with an error, and if so, what the error was.0844

Let's take a look at a file called exitDie.php.0849

And what it does is takes one GET parameter, the GET variable name.0853

And here, we use our ternary operator that creates a short variable name that gets set to the value provided, if one was provided, and null if not.0861

And then, we have a test that occurs, that uses this is_null function that we had learned about a few lessons ago.0869

that tests if the name is equal to null; then it is going to exit the script0875

and output a message saying that the GET variable name is required for this script.0880

That is the example we are going to use of these exit and die constructs:0884

when you have an error condition that occurs that your script can't run if that error condition occurs.0887

In this case, we are just going to say that the condition of not providing the GET variable name is an error condition that we have to halt the script for.0895

We call the exit function if name is equal to null; it outputs a string that the GET variable name is required for this script.0904

And then, it just says that the script is halting.0912

As soon as that message is output, the script halts at that point.0914

Even though we would exit out of this if statement right here, and go ahead and execute this echo statement,0918

that is not going to happen once we call this exit construct, because it halts the script.0924

Now, alternatively, if we do provide a name GET variable to the script called name, then is_null is going to return false.0931

We are not going to call the exit construct, and we are just going to output the name of the GET variable.0939

If we go and look at this file in the browser, exitDie.php, we can see that, if we call the file without providing any GET variable,0944

it says "the GET variable name is required for this script; script is halting."0952

So, that exit construct actually was executed.0956

Now, if we go ahead and provide a GET variable called name...just set it to some value...Matthew in this case...0959

we can see that it outputs the _GET variable with key 'name' is equal to the value 'Matthew'.0965

And the exit construct does not get executed.0971

And so, that is an example of the exit and die construct, which you may see in different code that is out there.0975

Now, I want to talk about an operator that is not used too commonly: it is called the execution or 'backtick' operator.0985

And it is denoted by a pair of backticks.0990

And what happens is: any time you include a string between a pair of backticks,0993

what it does is treats that string as a shell command, and it goes ahead and executes that.1000

It doesn't output the result of the shell command; for example, this is a Linux command to output a directory listing.1005

What it does is: it returns whatever output that shell command generates from the operation.1013

And you can store it in a variable: in this case, we are going to store it in this variable called dirListing.1021

And then, you can do with it what you want.1026

Additionally, there is also a function called shell_exec that provides the same functionality as this execution operator,1030

where you would call the function with whatever shell command that you want to execute.1036

For example, we could call it with ls -al, and so forth.1042

Let's take a look at this execution operator in action, which is something you may see in code.1048

Here, we have the execution operator that is just executing, in this case, a Windows shell command that is dir /w.1055

It just says to output the current directory listing.1064

Because this doesn't output the value directly to output, it returns the output of that shell command.1069

We are going to store it in the dirListing variable, and then we are going to use the echo command to output it as pre-formatted HTML.1074

If we go ahead and load the executionOp script, we can see that what gets output1081

is this pre-formatted code, which is the result of calling that dir /w shell command.1090

And so, that is an example of the execution operator.1099

Also, there are a couple of array operators out there that we haven't talked about before that are not used too often.1105

There are several--four, in fact--that are binary comparison operators, and they are just like comparison operators1111

that we have talked about before, except that they work when both operands of the operator are arrays.1117

There are the equality and inequality operators, which evaluate the same as they did before,1124

except that, for arrays, they evaluate to true if both operands, or both arrays, have the same key/value pairs.1130

So, the keys are the same and the values are the same.1137

And then, it returns false if they are not--if you use the inequality operator.1139

And just like the inequality operator for other variables, there are two versions of it;1143

and the most common version that you are going to see is the exclamation point with the equals sign.1149

There are also identity and non-identity comparison operators for arrays.1154

The identity operator evaluates to true if both of the array operands have the same key/value pairs1160

(meaning they have the same keys and the same values, and they are in the same order), and all of the values are of the same type.1166

And if that evaluates to false, then the non-identity operator (which is the exclamation point followed by two equal signs) is going to return true.1172

Additionally, there is also a union operator, which is the plus sign.1183

And what that does is: that is used to append any key/value pairs in one array to the key/value pairs in another array.1186

And what it does is takes any key/value pairs in the right operand that aren't in the left operand and appends them to that array.1199

Let's take a look at these array operators.1208

There is a script called arrayOps.php.1212

I have created three different arrays: one is an indexed array with the values 0 and 1.1215

And then, I have also created an indexed array that contains the values 0 and 1, with the keys (that are strings) 0 and 1.1221

This statement here just outputs these arrays.1229

And I have also created a third array that is an associative array, where the keys and values are both 0 and 1,1232

except array 3 differs from array 2 in that the order of the values is switched.1238

What that is going to mean is that, when we perform the identity comparison operation on these two arrays,1242

it is going to return false, because even though the key/value pairs are the same values, their order is different.1248

For example, what we do down here is: we test the equality operator.1255

And we say, "Is array 1 equal to array 2?" and in this case, it is going to return true, because both the keys and the values are the same,1258

because we know, for an indexed array, the key for the first value is 0 and the key for the second value is 1.1273

And in array 2, the key specified has the value 0 for 0, and the key specified for the value 1 has a value of 1.1279

So, this is going to return true; correspondingly, the inequality operator is going to return false.1287

So, if we go and load this script up (arrayOps.php), we can see that, for this set of arrays,1293

array 1 equals array 2 evaluates to true, so that equality operation evaluates to true.1302

Because it is true, then it can't be not equal, so it evaluates to false.1308

The other thing we are going to do is test the identical operator.1312

And what that is going to test is between array 2 and array 3.1318

And it is going to evaluate to false; and that is because, even though these arrays both have the same key/value pairs1321

(they both have a key 0 with the value 0 associated with it, and the key 1 with the value 1 associated with it),1326

however, their order is switched, so the arrays are not considered identical.1333

It is going to return false; and likewise, the non-identical operator is therefore going to return true.1336

If we look back at the code, the other thing I have done is created two associative arrays, one with two elements1344

where the keys are the abbreviations for the days Monday and Tuesday,1355

and the values are the full names of the days, with just the first letter capitalized.1359

I have created a second array with the same keys as in the first array, except the values are completely capitalized versions of the days.1364

And then, it also adds a third key/value pair for Wednesday that has the wed abbreviation and WEDNESDAY spelled out in all capital letters.1373

Now, when we perform the union operation (which, again, is used with a plus sign) from array 1 and array 2,1383

if we go back and look at the output, we will see what happens.1389

We can see that, when we perform the union of array 1 and array 2, the output that we get is an array that contains the key mon with the value Monday, the key tue with the value Tuesday, and the key wed with the uppercase value WEDNESDAY.1393

What happens is: any of the new or unique key/value pairs in the right operand get appended to the left operand's array.1411

Because Monday and Tuesday (or the keys mon and tue) were already defined in array 1, those aren't considered new key/value pairs.1421

So, the array keeps the values that it already had associated with those keys.1429

However, the key wed with the value WEDNESDAY does not exist in this left operand array, or array 1,1435

so it gets appended to the array; and you can see that it has the key wed with the value WEDNESDAY.1443

And so, that generates the union of those two arrays.1448

Now, I want to talk about a kind of tricky concept called variable variables that is used somewhat infrequently.1455

What it does is allows you to dynamically declare variables within your PHP scripts.1462

The way it does so is using what is known as a double dollar sign syntax.1467

For example, let's say we have a variable called str, and we give it the value firstName.1471

So, we define it as $str='firstName', which should be capitalized.1477

Then, if we use this declaration here, which is $$str, and then set it to some value 'Joe',1489

what we have done is created a new variable that has the name that is the value of string.1503

So, for example, we now have (if this was in the global scope) a variable also called firstName whose value is equal to Joe.1511

What happens is: in this double dollar sign syntax, when PHP sees that, it gets the value of the first variable, the rightmost variable.1525

It returns that value, and then it is just as if it had replaced it with the value of that variable; so it would be a dollar sign, followed by firstName.1539

Assuming that that variable wasn't defined already in our script (or even if it was), when we use this syntax right here,1549

and we set it equal to Joe, we create a variable called firstName and set the value equal to Joe.1555

That is a way of creating variable variables, or variables that have variable names.1561

If we look at variableVariables.php (which is a script), I have an array that contains two key/value pairs,1570

the first one being first with the value Joe, the second one being last with the value Smith.1579

What this array is: it is called varsToDefine, which means we are going to use these keys of this array1585

to define variables called first and last, using this variable variable functionality provided in PHP.1592

So, if this is all that is in our script, if we go and try to output the variables first and last,1599

we are going to get an error message saying that these variables don't exist, because they haven't been previously declared.1604

However, if we go ahead and loop over varsToDefine, and we pull out the key as the variable name to define,1609

and the value as the variable value, and then we go ahead and use this double dollar sign syntax,1618

what we are going to do is create a variable called first, and we are going to set it to the value Joe;1625

and we are going to create a variable called last and set it to the value Smith.1630

So now, when we go ahead and execute this section of echo statements that we also had up here,1634

PHP is going to know that there is a variable called first and know that there is a variable called last,1640

because we created them using this double dollar sign syntax.1644

And so, it would be able to output those values.1648

So, when we go and view this script in our web browser, we can see that, when we try to output first and last1651

at the beginning of the script, we get these undefined variable messages.1660

However, after we have looped over that array and created these variables dynamically, we end up creating a variable called first and a variable called last.1664

And so, when we try to output their values, Joe and Smith, we are able to successfully do that.1673

And so, that is an example of what variable variables are in PHP.1677

There is a similar concept to that that relates to functions, known as variable functions.1685

That allows for functions to be called dynamically by specifying the name of the function as a string.1690

For example, any time you append a pair of parentheses to a variable name in your PHP code,1697

PHP is going to try and execute a function that is named the value of that variable.1704

For example, if we have a variable called funcName, and it is set equal to the string time,1710

and then we were to execute the code or type the statement funcName and append it with parentheses,1721

what PHP is going to do is similar to how it works with variable variables.1732

It is going to replace this variable function name with the string that it represents.1736

So, it is going to remove this, and instead it is going to have the value time.1740

And then, it is going to try to execute a function called time.1745

And so, it is a way of dynamically calling a function, based on the string name of the function.1749

If we go and look at a sample file, variableFunctions.php, we have two functions that we have created, called firstName and lastName.1755

They return a string value that is the first name and last name of this person, Joe Smith.1762

And then, what we do is: we look for a GET variable called function, and we set whatever value the GET variable function was set to...1767

we set the variable function name equal to that.1780

And then, we use this concept of variable functions to dynamically call...in this case, you have the firstName function or the lastName function.1783

And the way we do that is: we supply the name of the function (via a GET variable) that we want to call.1791

So, we are going to supply a GET variable called function with either the value firstName or lastName.1797

The value funcName is going to get set to that value.1802

When we execute the statement here, PHP is going to replace this variable funcName with the value we provided via GET.1805

And then, it is going to try to execute a function that has that name.1813

And it knows to do that because of these parentheses that we have included.1819

If we go ahead and try and view this file in our web browser, we are going to see1822

a thing that says "undefined index on line 28" and "function name must be a string."1828

So, for example, the undefined index comes because we haven't supplied a GET variable to it yet.1835

And here, it is saying "undefined function" because function name doesn't have a value, because there was no GET value provided.1840

So, if we go ahead, for example, and supply the GET variable function, and set it equal to time,1846

what PHP is going to do is call the time function, which we learned about, which returns a UNIX timestamp for the current date and time.1854

And when we run the script, it is going to output the output of that function, which is the current UNIX timestamp.1861

Now, let's say we pass it a function that doesn't exist...just add some letters to this time...qtey.1869

And we try to run it: we get a fatal error, because PHP is going to try to call the function called timeqtey.1875

And that function does not exist.1884

And that is because, any time PHP sees a variable name followed by a pair of parentheses, it tries to call a function whose name is the value of that variable.1889

That ends today's lesson; it has been a pleasure teaching you this Introduction to PHP course.1905

Educator®

Please sign in for full access to this lesson.

Sign-InORCreate Account

Enter your Sign-on user name and password.

Forgot password?

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Sign up for Educator.com

Membership Overview

  • Unlimited access to our entire library of courses.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lesson files for programming and software training practice.
  • Track your course viewing progress.
  • Download lecture slides for taking notes.

Use this form or mail us to .

For support articles click here.