Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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.
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.