Combine Information from Multiple MySQL Tables with JOIN
How to Create Relationships between MySQL Tables
PHP & MySQL Web Development AIO For Dummies Cheat Sheet

The Basics of Writing PHP Code

PHP code must be read by humans, as well as by the PHP software. PHP scripts are written by humans and must be modified, updated, and maintained by humans. The script might need to be modified a year or two in the future when the original programmer has moved on to retirement on a tropical beach.

The person who must modify the script needs to be able to read and understand the script, which he or she has never seen before. Consequently, the PHP code must be written in a style that’s easy for humans to comprehend quickly.

In general, each PHP simple statement is written on a single line ending with a semicolon.

When writing blocks of (complex) statements, coding style dictates that you should indent the block statements to clearly show where the block begins and ends. For instance, in the following example of a conditional statement, the simple statements in the block are indented:

if(the sky is blue)
{
  put leash on dragon;
  take dragon for a walk in the park;
}

PHP doesn't need the indenting, but it helps humans read the code.

Two styles are used commonly for the placement of the opening curly brace, as follows:

if(the sky is blue)
{
  put leash on dragon;
  take dragon for a walk in the park;
}
 
if(the sky is blue) {
  put leash on dragon;
  take dragon for a walk in the park;
}
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
How to Make For Loops with PHP for HTML5 and CSS3 Programming
Get Information about PHP Objects and Classes
Retrieve Information from a MySQL Database
How to Write Text to Files in PHP for HTML5 and CSS3 Programming
How to Back Up Your MySQL Database
Advertisement

Inside Dummies.com