Chapter 0:Introduction
0-000.000 - About This Course

Chapter 1:PHP Basics
1-1.1 - Hit the ground running.
1-1.2 - A Simple PHP Program
1-1.3 - Formatting the code
1-1.4 - Comments in PHP
1-1.5 - Storing Data in Variables
1-1.6 - The print() Function

Chapter: 1 - PHP Basics


Lesson: 1.3 - Formatting the code

You will find that formatting your code with PHP is very forgiving. You can literally write the same statement in dozens of different forms and PHP will read it exactly the same every time. The only exception is that you would generally want to keep a statement on a single line. Of course there are exceptions to every rule, and we will get into that a little more in future lessons.

For now, just know that PHP does not generally care about whitespace (tabs, spaces, etc...). This can help the legibility of your code greatly. For example, consider the difference between our code in listing 1.2 and the code below in figure 1.3.

Figure 1.3, poorly formatted code.



Now, consider that the two pieces of code perform exactly the same function, with no difference in output to the browser. But, when you go back to work with the code later on, or pass it to someone else, you will be able to read and understand the code we had written in listing 1.2 but, listing 1.3 makes the task a little more difficult.

So what I am trying to say is that style is important, in any language. Good coding discipline will help out in the long run. It takes a little more effort and time but, it's worth it.