Join Mark Niemann-Ross for an in-depth discussion in this video The facts: Setting and displaying variables using built-in functions and their arguments, part of Teach Kids Programming with PHP.
Now that you've played with the code, let's talk about what you're actually doing. You've been primarily working with variables and functions. $myName equals Bob is a variable. date is an example of a function. Variables are a place to store things. Think of them like boxes with names, or colors. If I have a red box, I can put a ball in the box, and say something like get me the contents of the red box.
You'll hand me a ball. Then I can replace the ball with a hamburger and say the same thing. Get me the contents of the red box. You wouldn't hand me a ball, you'd hand me a hamburger. The red box is just like a variable. Any word inside the code brackets starting with a dollar sign is a variable In this program, we have three variables. $today, $my name, and $dialy menu.
Daily menu on line six is a special variable. It's an array, but we'll talk about that later. Describing a function can get really complex. So I'm going to keep it simple. Because of that, what I'm saying may not be 100% complete. But it's usable for this course. Functions are like mini programs written by someone else. Functions provide complicated actions. And you don't have to worry because someone else already took care of the programming for you.
Imagine that a function is like a man at a hot dog stand. You just walk up to the hot dog man and say, I'd like a hot dog. The vendor takes it from there. He assembles all the essentials of a good hot dog including the bun and the relish and packages it all together nicely for you. Then, he brings the finished product back to you. Whoa! Ready for eating! Now, a hot dog function might look like hotDog().
Functions in PHP always have a set of parenthesis, often with information for the function to use. For hotdog function, we could do something like hotDog("mustard"), which means I'd like a hot dog with mustard. We still get a hot dog, but the contents in parentheses modifies the function in some useful way. The date function uses the letters inside the parentheses to modify how the date looks.
Whatever is inside the parentheses is called arguments.
- Teacher's Guide: Introduces the concepts in the chapter and preps the adult on places where the student might get stuck
- Try It: Immediately engages the student, showing working code in action
- Check It Out: Encourages the adult and student to engage with and edit some existing code
- The Facts: A lecture for the student to watch
- Extend It: An exploration of expanded and extended concepts
- Challenge: A hands-on coding challenge for the student
- Solution: A step-by-step solution presented by the author
This course, in essence, acts as a lesson plan to help you teach PHP to a beginner. Its structured curriculum supports those who have a solid understanding of PHP, but don't necessarily know how to teach PHP effectively to kids.