That concludes the basic PHP part of our tutorials. You have just had a birds-eye overview of what is called “procedural programming” in php. Later we’ll get to “object oriented programming” in php.
I’d like to point out one last thing regarding for vs. foreach loops, you’ll use foreach loops way more often in PHP than you will for loops. The learning technique I would apply now is again to tuck this away for later, but do so like this: keep a look out for a practical problem where a foreach loop won’t solve your needs, and when that happens, re-read about for loops, and see if they provide the solution; try to imagine a for loop at some point in the future providing you with the solution you need. Otherwise, keep it moving, and don’t waste much more mind on this.
That’s another learning technique I apply: weigh the importance of certain subjects and keep it moving. Often, you’ll get your answers in later things you learn, and you’ll inefficiently waste time and energy trying to force the understanding of something you may never need, or something that will inevitably become clearer when you learn other aspects. So be OK with not necessarily fully understanding something or being able to see it’s practical use.
Some people may say it’s important to understand one thing completely before moving to the next. Being determined to learn something is very important. I agree, but with a big BUT. The but is that I usually re-read everything I study at least twice. So you’re going to be back here anyway. I’m viewing the real learning process in way more long-term approach, not just a wam bam thank you mam, “read it once and understood it completely,” which rarely happens.
Right now, if this is your first time through, you’re building a general understanding of the landscape you're tackling. This is what they call the “general to specific” way of learning, as discussed in the PHP 5 - How to Learn Programming tutorial. What I’m trying to do here is get you through the entire landscape of programming as quickly as possible to give you a birds-eye-view. Most of the time people give up because the teacher focuses too hard on each step prematurely, and just bores the hell out of the student, or confuse him/her because pieces/clues to aid the student are missing since they come from other aspects of the subject matter at hand. Usually those aspects can be picked up while getting the general overview of each aspect of the topic, as I'm doing here.
So the reason I’m teaching like this is because once you have that birds-eye-view framework, you can so much more easily dive deeper and learn the specifics. The reason this is true is because it allows you to see how things piece together. It allows you to see the practical application of things. It allows the neurons in your brain to start building a fuzzy somewhat distorted picture of the entire puzzle, but at least some sort of picture of how it all relates. That makes it so much easier to find and learn what you’re looking for later, and ultimately put those puzzle pieces in place. In essence, you'll now be on the hunt for specific puzzle pieces. That’s really the entire premise of my entire teaching/learning technique. Learn general to specific, and then dive into the sub-topics more, then sub-sub-topics, and so on. It gives you a sense of purpose when you decide to go back of your own volition and figure out a specific aspect of the whole subject matter. Your passion and enthusiasm--birthed from quickly getting an overview of the entire subject matter--make it so much easier for you to understand something. If you care to learn something you will. If you’re force-fed it (prematurely usually), you are more likely to be confused and waste your time.
The other approach is specific-after-specific. Here you’ll spend hours on one point when you’re not quite ready to learn it. With general-to-specific, easy to understand pieces of information from other areas of the top level subject matter will serve as clues to aid better understanding when you go back and dive into each specific sub-topic, and you’ll simply learn quicker. But don’t forget, the key ingredient is truly wanting to learn the subject-matter. Hopefully after getting a birds-eye-view of the entire subject, like I’m providing now, you’ll cultivate your own interest to learn more ;).
FINAL THOUGHT: it's very important to learn an entire subject matter. As a programmer-in-the-making, you may be inclined to take what you've learned and start coding immediately, but before you've learned enough of the topic at large. In reality this will lead to you coding away, and then eventually spending hours just to research how to solve one little aspect you need. If you learned the whole subject matter of, say, procedural PHP, you most likely will have naturally encountered that solution, and in a faction of the time! Often it can take very many hours to research one small solution that results in one line of code. Whereas learning that trick might have been a natural thing to learn as part of learning the whole subject, and only requires 5 minutes of study in between learning many other tricks. In other words, a developer that has to constantly seek out solutions to things he/she doesn't know will waste a lot more time in aggregate than someone that mastered the subject as a whole, and then went to apply it. You're just more relaxed and in a better learning mode when you're focused on nothing but learning. But when you're focused on producing results, and have to learn at the same time, it can be stressful and waste you tons of time going back and forth from testing each of the tens of wrong solutions you're trying out and googling until you find the right one.