Join Kevin Skoglund for an in-depth discussion in this video Scope and global variables, part of PHP Essential Training.
- [Narrator] We've seen how the variable names…inside the function and outside the function are unrelated.…We wrote a function to do addition,…the variable sum was only available inside the function.…We couldn't use echo outside the function…to retrieve that value,…we had to use a return value instead.…Having this division between the variables…inside a function and outside a function,…is known as variable scope.…A variable isn't accessible all the time,…it's only accessible within it's context.…A variable created inside a function…is by default only accessible in the function.…
We say that the function is the variables' scope.…In PHP, there are two main scopes.…There's the global scope, and there's the local scope.…Let's take a look at them so we can see the difference.…Let's start by taking basic dot html.…Calling save as on it.…We're going to call this functions underscore scope,…and I'm going to end it with PHP, save it.…Now let's create ourselves a little example here.…Let's call this functions scope.…I'll start my PHP tags,…
- What is PHP?
- Embedding PHP code on a page
- Inserting code comments
- Variables, strings, arrays, and Booleans
- If, else, and elseif statements
- While and for loops
- User-defined functions
- Function arguments and return values
- Debugging and troubleshooting
Skill Level Beginner
MVC Frameworks for Building PHP Web Applicationswith Drew Falkman2h 57m Intermediate
1. PHP Overview
2. First Steps
3. Explore Data Types
4. Control Structures: Logical Expressions
5. Control Structures: Loops
6. User-Defined Functions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.