Author: Robin Nixon
Pub Date: 2015
Size: 10 Mb
Based on the author’s successful online courses, this complete, integrated learning tool provides easy-to-follow lessons that feature clear explanations, sample code and exercises, and video tutorials.
Each lesson is designed to take you less than an hour to complete.
PHP: 20 Lessons to Successful Web Development covers the basics, including constants, superglobals, operators, and arrays. Next, you’l learn ow to work with multidimensional arrays, write unctions, manipulate objects, build web forms, anage security, use Ajax, and much more. ogether, the book and almost five hours of video training make learning PHP easier than ever!
Don’t worry if you are not clear about some of the subjects covered here, such as arrays (which are like collections of variables grouped together) and functions (sections of code you can call and that may return a value), because they will be explained as you progress through the lessons.
However, we actually covered quite a lot of ground in this lesson, which explained some of the simpler PHP syntax and data-handling capabilities. In the following lesson, we’ll start to see how these items come together with arithmetic operators to enable you to start creating simple PHP expressions.
When PHP encounters the || operator, it knows to check the left side first. So, if $ThisVar has a value of 1, there is no need to look up the value of $ThatVar, because as long as one or the other expression on either side of the || operator evaluates to TRUE, the entire || expression evaluates to TRUE, and if the left half has evaluated to TRUE, then so has the whole || expression. In cases such as this, the PHP interpreter will eagerly skip the evaluation of the second half of the expression, knowing it is running in an optimized fashion.
Knowing whether operators have right-to-left or left-to-right associativity can really help your programming. For example, if you are using a left-to-right associative operator such as ||, you can line up all your expressions left to right from the most likely to be TRUE to the least likely. Therefore, it’s worth taking a moment to familiarize yourself with the contents of Table 6-4 so that you will know which operators have what associativity.
With the filing cabinet, as with the small pot metaphor in Lesson 3, to assign a value you should imagine writing it down on a piece of paper, placing it in the relevant drawer, and then closing the drawer. To read back a value, you open the drawer, take out the paper, read its value, return the paper, and close the drawer. The only difference between the cabinet and the pots is that the drawers of the filing cabinet (representing an array) are all in sequential order, whereas a collection of pots (representing variables) are stored in no particular order.
Although PHP arrays can be any size (up to the available memory in your computer), for the sake of simplicity I have only shown 10 elements in the figure. You can access each of the elements in an array numerically, starting with element 0 (the top drawer of the cabinet). This index number is important, because you might think that logically the number 1 would be the best starting point, but that isn’t how PHP arrays are accessed—you should always remember that the first element is the zeroth.