I'm new to these forums and completely new to PHP. I'm currently working through Kevin Yank's "Build Your Own Database Driven Website Using PHP & MySQL", and am only on Chapter 3.
I'm trying to understand the theory behind the way most php is written... as far as when a new line is created, where opening and closing braces are placed, etc.
For instance, this first example looks more readable and understandable to me (especially the braces beginning and ending on the same line):
Code:$firstname = $_REQUEST['firstname']; $lastname = $_REQUEST['lastname']; if ($firstname == 'Kevin' and $lastname == 'Yank') {echo 'Welcome, oh glorious leader!';} else {echo "Welcome to our website, $firstname $lastname!";}
Why is it written like this (which seems confusing and a much easier way to miss an opening or closing brace)?
Code:$firstname = $_REQUEST['firstname']; $lastname = $_REQUEST['lastname']; if ($firstname == 'Kevin' and $lastname == 'Yank') { echo 'Welcome, oh glorious leader!'; } else { echo "Welcome to our website, $firstname $lastname!"; }
I'm happy enough to simply learn the correct way to do it. I'm just curious what the reasoning is behind it.










Bookmarks