Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
 
Old January 20th, 2005, 09:21 AM
Authorized User
 
Join Date: Dec 2004
Location: Dallas, TX, USA.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ababb
Default 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
 
Old January 20th, 2005, 11:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

{} 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.
 
Old January 20th, 2005, 11:47 AM
Authorized User
 
Join Date: Dec 2004
Location: Dallas, TX, USA.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ababb
Default

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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Help required zaeem SQL Server 2000 2 May 28th, 2008 12:48 AM
Some help required ! codenet C# 2005 1 September 24th, 2007 04:01 PM
What's the use of braces in a string literal? aaaa0441 Pro PHP 7 January 20th, 2007 04:23 AM
What's the use of braces in a string literal? aaaa0441 Beginning PHP 4 January 14th, 2007 08:10 AM
Chapter 2 {curly bracket} parse error of DEATH psychot BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 3 August 5th, 2005 03:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.