Learning PHP with Programming Exercises
PHP Is Everywhere
You know about PHP, how it's taking over the Web, found on over 20 million domains. You've probably already started to learn the language, either through online tutorials, classes, or books. Or a combination. Now you want to practice your skills, try your hand at writing some scripts on your own.
Beginning to Write Your Own Scripts
When you create your first scripts, it's nice to have some direction. If you are taking a class, that's not a problem. But if you are using online tutorials or books, finding direction can be difficult. If you try to create something from scratch and run into a problem, you can get frustrated trying to figure out what isn't working right. What you need are programming exercises. Exercises for PHP can be really hard to find on the Web. The few that do exist usually don't provide the answer script, much less the output from the script.
Books are great and usually do include some programming exercises with answer scripts. But in the hectic editing process, some scripts end up with errors. Once again, you can be stuck not knowing what went wrong.
Beginner PHP Books
This is when a site like phpexercises.com can give you a big boost, help you write scripts and gain confidence. Exercises start at the very beginning, with simple text printed to the browser, and go from there. If you have spent any time with PHP, you should be able to find an exercise suited to your level of proficiency. Included are variables, loops, conditional statements, forms, arrays and functions.
In the screen shot below is an example exercise. To use the exercise, you follow the instructions, writing and testing the script on your own computer. When you have it functioning properly, you click the 'View Script' button (circled in red) back on the exercise page.
Seeing the Answer Script and Output
When you click the button, you see the script, as in the image below. Comments in green explain some of the workings of the script. If you follow the link at the bottom (circled in red), you can bring up the output from the answer script. This shows you that the script has been tested and works, and might help you troubleshoot your own.
Try It Yourself
If you are a beginning to intermediate PHP programmer, visit phpexercises.com and test your skills.
HTML Books - The more HTML you know, the better for programming with PHP.
Sites and Pages Referenced in this Lens
- PHP Exercises
PHP exercises for beginning to intermediate programmers. Includes variables, operators, control structures, forms, arrays, functions.
- PHP Control Structures Exercise #4: Nested For Loops
In this PHP exercise, the programmer uses nested for loops to create an HTML table of multiplication tables.