If you read PHP 4 - SCOPEyou may have noticed i left you with what might seem like a vague description of scope. Accordingly I would like to point out something very important about how I’m writing these tutorials: my main goal in writing these tutorials is to come at an angle of teaching (and learning) that is very different from everything else out there. Specifically, my goal is to teach you the techniques I’ve learned that help me learn better. So in other words, my goal is not just to teach you programming, but to teach you how to learn programming (and how to learn in general). That will help you learn programming way faster. That said, what I wrote in PHP 3 - FUNCTIONS about “implant in your head...” is a very important technique I have while learning a subject.
Basically the technique goes like this: if there’s a concept I don’t fully understand, but I know is central to learning the subject matter, I file it away in my brain as something noteworthy that i’m inevitably going to have to understand, and look out for more lessons and explanations that will further explain it and help me grasp it.
The next bit is I'm teaching programming accordion to the "general to specific" formula of learning. Think about it like a well written college thesis--you introduce your readers to the subject at hand, providing an outline of what will be explained, and gradually take the reader deeper. So rather than hit you with specific after specific whose connection might not be clear, I skim over the subject generally to give you the bigger picture concept you can easily understand. What this does is both inspire you to go deeper, and make it easier to understand the specifics you dive deeper into. After learning the birds-eye-view terrain like this, you'll be hungering to learn more. Teaching specific after specific is what how they teach you in school. They force-feed specific after specific because the assumption is you don't want to learn, and don't really care about the bigger picture, let alone any of it. So traditional teachers will just inject the raw skills, e.g. Calculus, into you, but you barely know what you need it for or how it fits into the bigger picture of math as a whole. So while kids may have no interest in the bigger picture, the assumption here is that you're hungering for what I'm teaching you, and can take the time and be patient to first learn the birds-eye-view general explanation of the terrain you're about to cover in more detail.
The final bit about this is that I actually gave you that "gotcha" you should file away. Most of the time when reading these tutorials on the web or in books--though written by very capable of authors--they do not give you that nugget, or rather that seed which will grow. And often that means you’re left with an unconfident feeling. I find it better to give you something that will make you feel confident about the true baby steps necessary to grasp the subject matter. That’s what will lead to you not giving up, and the neurons in your brain forming the proper conclusions on your own, so next time you come back to the subject matter you’re stronger. The point is it's a lot easier to understand these general overviews, than the exact specifics. However, once you understand the general overview of the terrain, the specifics become easier. It’s just like as if you’re working out and work out too hard and pull a muscle, and can’t come back for a long time to train again, but if you took the proper baby steps you’d be back at the gym the next day still growing your muscles.
So I’ll reiterate, here the seed that has a high likelihood of growing into a tree/muscle is:
“Scope means variables at different levels of the code can have the same names and are not the same variable.”
Again, that’s not the complete definition, and it’s put in very layman’s terms, but should give you an idea of how different pockets of code are connected and how they’re not. In the case of functions, they’re specifically connected in 2 places:
1) on input via the parameter passed in between the parentheses halveMonth($parameter);
2) and the output when the result is assigned through an equal sign back to a variable in the current client code scope: