 |
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6  | This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

January 20th, 2005, 09:21 AM
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Where are Curly Braces required?
I don't understand the use of Curly Braces.
On p74 they are used with a foreach command.
On p75 they are used with an if statement.
On p82 they are used with a while statement.
On p118 they are used with a function.
On p131 they are nested:
They are used with a for statement which is nested within a function, which also uses them.
Once you understand when they are required, how do you know where in the code they belong?
What function do they serve, are what are the rules on their placement within the code?
ABabb
Dallas TX
__________________
ABabb
Dallas TX
|

January 20th, 2005, 11:28 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
{} are used to show the start and end of what's called a statement block. For example if you write something like
if (a==b)
command1;
command2;
command3;
...how does PHP know which of command1,2 and 3 are only to be executed if the condition a==b is true? The answer is the {}. If you write:
if (a==b)
{
command1;
command2;
}
command3;
...that means execute command1 and 2 only if a==b, and always execute command3.
So {} are needed in any sort of language construct where PHP needs to know how many following lines of code are associated with a statement or condition.
If there are no {} following a statement like if, while, foreach then that means only the following line is subject to the condition.
To answer your other question about ==, I assume you're asking why its not just =. The answer is that = is the assignment operator, i.e. its used whenever you want to *assign* a value to a variable. == is a comparison operator, so you should use it whenever you want to *compare* values.
|

January 20th, 2005, 11:47 AM
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you so much. Your explanation really helps, and this kind of in-depth explanation is not in the book.
I like the book, but it seems to really understand the code as against just typing it in to see if it works I have to ask more questions.
So I appreciate you and your colleagues out on this site. I think I can become competent if I can learn the language.
Bye for now,
ABabb
Dallas TX
|
|
 |