Matthew M.

Matthew M.

Expression & Operators

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
Bookmark & Share Embed

Share this knowledge with your friends!

Copy & Paste this embed code into your website’s HTML

Please ensure that your website editor is in text mode when you paste the code.
(In Wordpress, the mode button is on the top right corner.)
  ×
  • - Allow users to view the embedded video in full-size.
Since this lesson is not free, only the preview will appear on your website.
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Transcription

  • Related Services

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.
  • Learn at your own pace... anytime, anywhere!

Expression & Operators

  • An expression is anything in PHP that has a value.
  • An operator takes one or more expressions, called operands , and performs some operation on them to yield another expression.
  • Operators can be divided according to how many values they operate on:
    • unary operators: single value
    • binary operators: two values
    • ternary operators: three values
  • Assignment operators (=, =>) are binary operators used to assign the value of one expression to another expression .
  • There are arithmetic operators for addition, subtraction, multiplication, division, and negation. There is also the modulus (%) operator used for getting the remainder of a division operation.
  • The increment/decrement operators are used to increment or decrement their operand by one. They come in both pre and post forms.
  • The concatenation operator (.) is used to combine two strings into one.
  • PHP provides combined assignment operators for all of the binary arithmetic operators, as well as the concatenation operator.
  • Operators have both a precedence and associativity .
  • When an expression contains multiple operations, the operations with higher precedence are completed first. If an expression contains two operations of equal precedence , then the associativity of the operations determines which operation is completed first.
  • Additional Resources:

Expression & Operators

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
  • Expressions 0:41
    • Expressions Definition
    • Example: Literals
    • Example: Variables
  • Operators 1:44
    • Operators Definition
    • Unary, Binary, and Ternary Operators
  • Assignment Operators 2:52
    • Assignment Operators
    • Array Assignment Operator
  • Arithmetic Operators 6:15
    • Operators for Common Arithmetic Operations
    • Modulus Operator
    • Arithmetic Operators Example
  • Increment/Decrement Operators 10:48
    • Increment/Decrement Operators
    • Pre- and Post- Increment/Decrement
    • Coding Example
  • Combined Assignment Operators 16:44
    • Combined Assignment Operators
    • Combined Assignment Operators Examples
    • Coding Example
  • String Operators 20:28
    • Concatenation Operator, String Variables, and String Literals
    • String Operators Example
  • Precedence & Associativity 23:40
    • Precedence & Associativity
    • Expression Containing Multiple Operations
    • Expression Containing Two Operations of Equal Precedence
    • Using Parentheses to Force Precedence
    • Precedence & Associativity Review
  • Homework Challenge 31:08
    • Homework Challenge

Transcription: Expression & Operators

Hello, and welcome back to Educator.com's Introduction to PHP course.0000

In today's lesson, we are going to be covering what are known as expressions and operators.0005

Specifically, we are going to be going over what expressions are and what operators are.0012

Then, we are going to go through a number of different operators that are available (and operators are things like addition, subtraction, and so forth).0018

And so, we are going to have a couple of slides going over a number of different operators available in PHP.0025

We are also going to go over a topic known as precedence and associativity,0031

which is like rules that apply when you do multiple operations at the same time.0036

What is an expression? That is part of what the lesson is titled.0042

Well, in PHP, an expression is anything that has a value; so literals have values, variables have values--they are all considered expressions.0046

For example, here we have three different literals: an integer, a float, and a string.0056

Those, obviously, are literal values; they have a value; they are considered expressions in PHP.0060

Additionally, variables have values; you set values to them.0066

Here we have an example of three different variables; we have a regular variable, an indexed array, and an associative array.0070

All of those have values, and they are considered expressions in PHP.0080

In this lesson, we are also going to be learning about operations, which are expressions in themselves, which means they have a value.0084

And then, in other lessons, we are going to be learning about constants, functions, and objects, all of which are expressions, as well.0092

And again, "expression" is just a synonym for something that has a value.0099

Operators work on expressions; an operator will take one or more expressions or values, which are referred to as operands,0105

which you may remember from your algebra days.0116

It performs an operation on those two expressions, those two operands, to yield another value for another expression.0119

The operators can be divided into categories, based on the number of operands they work on.0128

The ones that you are probably most familiar with would be something like an addition; you have 5+1.0133

It is what is called a binary operator; it has two operands--it has the 5 and the 1 that it operates on to yield a value.0138

In PHP, there are a couple of what are known as unary operators; and they are operators that work on a single value.0148

The majority of the operators we will see are binary operators for things like addition, subtraction, and multiplication.0155

PHP has one operator that has three values, known as a ternary operator.0162

But the majority of the operators are all binary.0168

The first operator we are going to specifically talk about is the assignment operator, and this is something we have already been using in our code.0174

We have already been using an operator, and maybe didn't even realize it.0182

An assignment operator is a binary operator, and as you know, it is used to assign the value of something to a variable, for example.0186

Basically, what that means in operator parlance: it is assigning the value of one expression to another expression.0195

For example, with the assignment operator (which we know is the equal sign), we have this expression here, 98.6, a float,0204

and we have this expression over here, bodyTemp, the variable.0211

The assignment operator says "Take this value and assign it to the variable on the left."0215

We have two expressions there.0225

Also, we have seen the array assignment operator, which is the equal sign followed by the greater than.0228

We have seen that in associative arrays where we have a key, and the way we associate a value in this case...0235

maybe Sunday it was 75 degrees; we associate the number with it using the array assignment operator.0241

And again, it takes the expression on the right-hand side and assigns it to the expression on the left-hand side.0247

Now, because both of these operators (the equal and the array assignment operator) are operators,0255

and we learn that operators work on one or more expressions to yield another expression,0262

these operations that we have seen up here (let me erase this) actually have a value.0268

It may not seem like it does, because normally you have something like 5+1, and you know that you have two operands and it yields a value of 6.0275

Well, this--because it is an operator, it has two expressions; it is a binary operator; it actually has a value itself.0284

This whole operation itself is an expression and has a value.0291

For the assignment operator, the value of the operation is the value being assigned.0296

And the way this might seem more apparent is: let's say we want to set a and b both equal to 5.0301

We have an expression like this, which is a legal statement in PHP.0315

PHP, with assignment operators, evaluates the one on the right first.0323

So, what PHP is going to do is: it is going to take this operation; it is going to assign the value 5 to the variable b.0327

And the value that that expression yields (which, for the assignment operator, is the value being assigned) is 5, is going to be assigned to a,0336

which makes sense, but it is essentially as if we had written it like this--if we had done it explicitly,0346

because when we assigned the value of a to the value of the assignment operation b=5, a gets assigned the value of 5.0362

There are arithmetic operators in PHP, as in most programming languages; and they have operators for all of the different typical arithmetic functions.0376

There is an addition operator and a subtraction operator.0387

You can do multiplication and division; and in PHP, like most programming languages, the multiplication operator is an asterisk.0390

So, if you want to multiply two numbers together, you would write it like...5 times 5 would look like that.0400

And the division operator is a forward slash; and so, if you want it to say 6 divided by 3, you would write it like this.0408

These four are all binary operators: addition, subtraction, multiplication, and division.0418

There is also the negation operator, which is a unary operator; that just takes the value of its operand and returns the negative version of it.0425

For example, if we have a=-5, this minus sign is the negation operator; it is saying to take the value of its lone operand, 5,0436

make it negative, and then the expression of value that that operation yields is -5, and so -5 is what is going to get set to a.0452

There is also another arithmetic operator known as the modulus operator, which is specified by the percent sign.0463

It is not as well known, but what it does is: it is basically a remainder function, so when you divide your numbers, it provides the remainder.0471

For example, if we have 7, modulus operator, 3, the result is going to equal 1; and the reason for that is:0480

if we divide 7 by 3 (go back to our elementary school math days), and we get 1, the remainder is 1.0487

And so, that is what this function outputs; that is a function to output remainders.0499

Let's take a look at a little code to demonstrate some of the different operators, which we will be able to look up from the Educator website,0505

basically just showing all of the different operators in action.0515

We are going to look at the HTML version of the code, because it's prettier and easier to look at.0519

For the addition operator, it is simply: as a binary operator, you take a value on the left and a value on the right.0526

It adds them together, and the result is, in this case, assigned to the variable a.0532

Here, if we have num=1, and then we add 1 to it, it is going to equal to, and a gets equal to 2.0538

All of the other arithmetic operators work intuitively the same sort of way.0545

For subtraction, if we have num set to 5, and we subtract 1 from it, the result of this operation is going to be the expression or value 4,0549

so a is going to get set to the value of 4.0559

And so on for multiplication and division: 2 times 2 equals 4; 6 divided by 3 equals 2; this is fairly intuitive.0562

The negation operator, which, as we mentioned before, is a minus sign, which is the same as the subtraction operator--0570

the way it is determined what it is going to be used as is the context it's in.0577

If it has two operands, it is treated as a binary operator, which means it's a subtraction operation.0580

Down here, it has one operand, the num variable; and so, this operator, the negation operator (let's blow this up a little bit) here--0588

the minus sign--says "Take the value of my one operand, num; negate it, and then set it equal to a."0598

So, in this case, a is going to be equal to -1.0608

And down here, we have this same modulus operation we had shown on the previous slide, 7%3.0611

That results in a remainder...when you divide 3 into 7, you get a remainder of 1, so a, in this case, is going to equal 1.0621

Just one thing to note is that the equation 7%3=1 is spoken "seven mod three equals one"; that is how you say it.0627

Like here, you would say, for division, "five divided by five equals," if it was a modulus operator, you would say, "seven mod three."0636

And so, that is how you speak it.0645

There are also what are known as the increment and decrement operators; what these operators do is:0650

they are unary operators--they operate on one value--and they increment or decrement the value of their operand by 1.0656

For example...first of all, they are represented by two plus signs and two minus signs together; this is the increment operator, and this is the decrement operator.0665

For example, we have variable i=0; right now, at the end of this statement, the value of i is equal to 0.0678

Now, we are going to perform the increment operation; we take the variable i, and we prepend it with the ++ operator,0687

the increment operator, which says, "Take my operand and increment it by one."0697

So, because i was equal to 0, and we have incremented by 1, at the end of this operation, i=1.0704

Likewise, for the decrement operator, it does the opposite: it subtracts 1; so this says, "Take the value of i and subtract 1 from it."0711

And again, that is two minus signs.0721

And so, because i previously was one, and we decrement it, i is now equal to 0.0722

There are kind of two operations going on at once here: i++, which...we will see there are actually two forms of the increment and decrement operators...0728

there is a pre form and the post form; this is the post form; they essentially mean the same thing, as far as incrementing or decrementing goes.0740

This says, "Increment the value of i."0746

It is essentially equal to if we had written the statement i=i+1; so, it's kind of an addition operation (we take the value of i; we add 1 to it),0749

and then an assignment operation, where we assign it back into itself.0759

Now, as mentioned, there is a pre form and a post form, and that is...either the operator goes before the variable, or it goes after the variable.0764

What that does is: because this is a combined operator of an addition and an assignment, whether you do a pre operator or a post operator0776

determines what value is yielded by this operation, because we know operations take one expression,0784

perform some operation on it, and yield another expression.0793

Well, with the pre increment operator, the value of the expression ++j is the value of j after it has been incremented.0796

So, if we assume j is 0 to start off with, and then we use the pre increment operator and set it equal to 1,0805

j is going to be equal to 1, because it has been incremented; and num is also going to be equal to 1.0813

Now, if instead we used the post increment version, where we have the operator after the variable name,0818

with the post increment operator, the value of the operation is the value of the operand before it is incremented.0826

So, right now, j is equal to 1 from the previous line where we incremented 0 to 1, the value of this operation,0835

because it's a post decrement, is j before it gets incremented.0843

So, num2 is actually going to get set to the value of j beforehand, which is 1.0848

So, num2 is going to equal 1; then j gets incremented, and j equals 2.0853

It is two different ways of using those operators.0859

Typically, you don't see the post one as often; typically you see the pre increment one, because it's a little less confusing.0864

When you use the post increment operator, I personally don't like to use it in my code, because it makes things a little less intuitive.0874

It adds some complexity to your code, because you have to think, "Well, is this setting the value before I've incremented it, or after it?"0882

So, in general, you don't see the post operators that much.0888

The thing that we will be using these operators for, mostly, is when we get to loops, which are ways to repeatedly go over lines of code.0894

Basically, they use a counter, and we use these pre increment operators0904

to continually add one to the counter each time it goes through the loop, for example.0909

If we look at another page that demonstrates some of these operations, we can see some of the same things that we went over here.0915

We have a variable num=1, and we pre-increment it; the value of num is going to be incremented, so num is going to be equal to 2.0924

Then, that value is going to be set to a, so a is going to be equal to 2.0933

We reset the value of num to 1, and then we set a equal to the value of the post increment operation on the variable num.0937

Well, the value of the post increment operation is the value of the variable before it's incremented,0947

so a is going to get set equal to num, which here is 1, so a is equal to 1.0952

Then, num is going to be incremented, so num equals 2.0956

So here, in this one, a and num end up having the same value at the end of this statement; here they have different values.0959

This, likewise, applies for the decrement operators, as well.0967

So, for example, if we have num=1, and we do a pre decrement on it, both a and num end up having the value of 0.0970

Now, with the post decrement operator, it's just like with the post increment operator.0981

The value of this operation is the value of num before it's decremented, so a is going to be equal to 1, because that is what num is set to.0985

And then, after num gets decremented, num gets set to the value of 0.0995

Those are the increment and decrement operators.1000

There are also what are known as combined assignment operators, kind of like what we just saw with the increment operator.1006

PHP has them for each of the different arithmetic functions, so they each have the corresponding combined assignment operator.1013

For example, the addition combined assignment operator is a + followed by an equal sign.1022

This is the one for subtraction, multiplication, division, and modulus.1026

Basically, it is kind of like when we had i++, we said that was the same as if we did i=i+1; that is kind of how these combined assignment operators work.1031

So, if we have num+=10, it is the same as saying "num is equal to the value of num, plus 10..."1050

What it does is adds 10 to whatever num is, and then reassigns the value to that variable.1063

It is kind of like the increment operator, except that here we have 10, and the increment operator always increments (or decrements) by 1.1072

Here, with the += operator, we can add however much we want to the variable.1080

This assignment is equivalent to this; and again, it's a combined assignment operation, because the first thing you have1089

is an addition operation that occurs: you take the number, and you add 10 to it.1095

The result of that--the value of that operation--is then assigned back into num.1099

Here are some more examples: if we start off with num=10, and then we do num+=10, at the end of this statement,1104

the value num is going to be equal to 20, because we have taken num's value, which was 10, added 10 to it, and reassigned it back to num.1112

Now, if we use, for example, the multiplication combined assignment operator, this says,1122

"Take num, multiply it by 5, and then store the result of that back in num."1128

So, up here, num was equal to 20 at the end of this statement, so 20 times 5 is 100; so at the end of this operation, num equals 100.1134

A similar pattern follows; if we do num and then use the combined division assignment operator,1144

it is going to say, "Take the value of num (which is 100), divide it by 4, and set that back to be the value of num."1151

So in this case, num equals 25.1156

And then, the modulus operator--the same way: it is going to say, "Take the value of num (which is 25); mod it with 6;1158

and store the result back in num," and just to show the mod operator again: you do...6 goes into 25; we get a remainder of 1.1166

So, that is why this is equal to 1.1176

We have a page that demonstrates this as well; and this page kind of echoes what we have just done.1180

It shows how all of these look in code; we have a variable name, and then here, we have done the += operator.1188

That is going to result in the value of num, incremented by 10.1196

Here we have the -= operator, which is going to say "subtract 10 from the previous value of num and set num to that value."1202

So, num is going to be equal to 1 here.1208

Here, we see the multiplication combined assignment operator again; so it is going to say, "Take num and multiply it by 20."1211

So, num is going to be equal to 20.1215

Here we divide it by 4; num is equal to 5; and then, mod...you end up with num=1.1217

Now, we are going to talk about string operators: there are two string operators.1230

Well, it's one string operator known as the concatenation operator, and then it has a combined assignment version, just like the arithmetic operators.1236

The concatenation operator is simply a period, and it is an operator that is used to combine, or concatenate, two strings together.1245

It is a binary operator; so here we have the binary operator, the period.1256

And it has two operands: on one side is hello--the string literal hello; on the other side is world.1260

And this operator says to take these two values, these strings and concatenate them together, and the result is the string concatenated.1268

So, the message (at the end after this concatenation operation occurs) becomes the literal "hello world" where they are all combined into one string.1277

You can use this with both literals and variables.1292

For example, we could create a variable called day and set it equal to Monday, and then we could create a variable that's going to hold a message.1295

We started off with a string literal, "Today is", and that is one operand of the concatenation operator.1303

The other operand we can set to the variable day, and what that is going to do is concatenate these two strings together.1311

It is going to take "Today is" and combine it with the string that day represents, which is Monday,1318

and output that as one string, and set it equal to message.1324

So, at the end of this, message is going to be equal to "Today is Monday."1327

Now, just like the other operators, the arithmetic operators, there is a combined assignment version for this one, too.1333

That is this here--the .= ; and basically, it is just like how the arithmetic ones work in that, if we have begin.=end,1339

that is saying, "Take the variable being, concatenate it with end (the operand on this side of the operator), and then assign that back into begin."1349

Let's take a look at a page demonstrating this.1364

This demonstrates the two examples that we saw: we have a string hello, and what we have done is saved it in message.1370

And then, we have taken the variable message, which is equal to the string hello, and we have concatenated it with the string literal world.1380

So, at the end of this operation, message is equal to the string literal hello world.1388

We could also do the same operation using a combined assignment operator, where if we set message equal to hello,1394

as we did up here, instead of having to write a full expression like this, we can just do .=world.1400

What that is going to do is just concatenate the world string to the string that message already is, which is hello.1406

And so, again, at the end of this, message is going to be equal to hello world.1412

Now, one thing I want to talk about to finish up the lecture is a topic known as precedence and associativity.1421

Basically, all operators have assigned to them a precedence and an associativity.1428

What those are for is when you have multiple operations occurring in the same statement.1433

For example, this statement right here has two operations: it has a multiplication operation, and it has an addition operation.1438

When PHP sees that, it has to have rules as to which operation it proceeds with first.1449

It could go left to right and say, "OK, I'm going to do 5 times 6 first; the value of that is 30, plus 2, and the value is equal to 32."1454

It could go the other way and say, "6+2 is 8; 8x5 is 40."1463

Well, the rules in PHP are that multiplication has a higher precedence than addition.1469

So, when those two operators occur in the same statement, the one with the higher precedence, multiplication, gets completed first.1475

It is sort of the same thing as if we had written this in parentheses here.1482

The value of this expression is actually 32, and not 40.1485

And actually, if you go...I have a link on the homework challenge to the PHP website and the PHP manual;1492

there is an operator precedence page, and what it does is: it lists all of the different operators, and most of these we haven't seen yet,1499

which you can just ignore for now.1505

And it ranks them in decreasing precedence; for example, as you can see, multiplication and division are at a higher level than addition and subtraction.1507

So, as we can see in the last example, multiplication happened first.1521

Now, what happens then, and the way this chart works, is that everything on the same line has the same precedence.1527

So, what if you have two operations that are occurring in the same statement where both operators have the same precedence?1533

Well, then you defer to what is known as associativity.1541

What that does is determines, "If you have operators in the same precedence, do they get evaluated left to right or right to left?"1546

So, go back and look at the slide here: the multiplication sign and the modulus operator both have the same precedence.1554

In order to decide which one gets operated on first, PHP defers to the rules of associativity.1566

The associativity for these operators is left, which means they get operated from left to right fashion.1572

So, what is going to happen is: 3 times 3 is first going to get multiplied, and then it's going to be mod-ed with 2,1578

as opposed to the other way around, 3 mod 2 times 3.1586

The result of this is actually 1 and not 3, because 3 times 3 is 9, and if you divide it by 2, the remainder is equal to 1,1594

as opposed to 2 goes into 3, remainder of 1, 1 times 3 is 3.1604

This demonstrates left associativity.1609

Now, as we saw in a previous slide, the assignment operator is right associative; so when we have a=b=5, this statement contains two assignment operations.1614

It has two assignment operators; they have equal precedence; so how does PHP decide which operation gets performed first?1630

Well, the associativity rules say the assignment operator is right associative, so the right one is going to get performed first,1639

and then move to the left, so then the left one will be operated.1646

As we saw before, b=5 gets operated first; that assignment operation occurs,1651

and we know that the value of an assignment operation is the value that was assigned.1655

This one occurs first, and then that value was assigned into a; so the assignment operator is an example of a right associative operator.1661

Now, one other thing that you can do, which you may remember back in math days, is force precedence using parentheses.1672

So, as up here, we had seen that, since multiplication has a higher precedence, it gets evaluated first, so we have 5x6 is 30,1680

and we add 2 to get 32; if we wanted to do reverse and add 6+2 first, and then multiply times 5,1688

we can force the precedence by adding the parentheses.1695

What that is going to do is tell PHP, "let me do what is in parentheses first: 6+2 is yielding 8; then multiply that times 5," so that is how we get 40 here.1698

The same way for this other operation: because, in this case, the multiplication and modulus operator have the same precedence,1707

associativity determines which operation occurs first, and associativity for these operators is left, so multiplication would go first.1716

By adding the parentheses here, we are saying we want to do this operation first; so 3 mod 2 has a remainder of 1, so it's equal to 1.1725

1 times 3 equals 3; so now, the value of the equation changes.1733

I have some examples of that, as well.1740

Basically, this is just a review of what we talked about; and we talked about precedence, saying that operations with higher precedence execute first.1748

In this case, which is a little bit different and shows the importance of precedence (because normally we read left to right,1758

and we would think this operation occurred first), in this example, multiplication has a higher precedence, so 2x3 is executed first,1766

which is equal to 6+5, is equal to 11; not 21, which would be the case if we added 5 and 2 and got 7 and multiplied it times 3.1773

Now, this example down here demonstrates associativity; again, the modulus operator and the multiplication operator1782

both have the same precedence, so the rules of associativity apply,1788

which say the leftmost operation gets performed first, and then it proceeds to the right.1792

In this case, 11 mod 3...3 goes into 11 three times with a remainder of 2, so we get 2 times 2; this results in num being equal to 4.1797

That is not 5, as if we had done this instead--if we had done the multiplication operation first.1809

For example, if these were right associative operators, we would have 3 times 2 is 6; 11 mod 6 is equal to 5.1817

And so, you just want to note that these have left associativity;1827

and as we talked about before, some operators, like the assignment operator, have right associativity.1830

And again, you can use parentheses to force precedence; so these examples that were shown above are now shown with parentheses,1836

to have them operated a different way: in this case, we can get the value to equal 21 by forcing the addition operation,1843

the lower-precedence operation, to happen first.1849

And then here, whereas the multiplication has the same precedence as the modulus operation,1852

but those operators are both left associative, we can force the right operation to occur first with parentheses.1859

For today's homework challenge, what I would like you to do is to go out and take a look at this link.1870

It's on the PHP manual, and what it does is shows you all of the different operators that are available in PHP.1874

And you can, like I said before, ignore the ones that we haven't covered yet, but you can see where all the different operators rank,1882

because when we eventually start writing arithmetic functions, and doing calculations, it is going to be important to know how they work.1889

And so, here, you can just see how the precedence works, and you can see that multiplication and division and modulus are higher up1897

in precedence than the plus or the minus or, in fact, the concatenation operator, as well.1904

That ends today's lesson; thank you for watching Educator.com--I look forward to seeing you next time.1911

Educator®

Please sign in to participate in this lecture discussion.

Resetting Your Password?
OR

Start Learning Now

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

Membership Overview

  • Available 24/7. Unlimited Access to Our Entire Library.
  • 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 lecture slides for taking notes.
  • Track your course viewing progress.
  • Accessible anytime, anywhere with our Android and iOS apps.