print "$counter times 2 is ".($counter*2)."<br>"

This is a discussion on "print "$counter times 2 is ".($counter*2)."<br>"" within the PHP Forum section. This forum, and the thread "print "$counter times 2 is ".($counter*2)."<br>" are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1  
Old Dec 10th, 2003, 04:21
Reputable Member
Join Date: Aug 2003
Location: Singapore
Posts: 321
Thanks: 0
Thanked 0 Times in 0 Posts
print "$counter times 2 is ".($counter*2)."<br>"

ok; sirkent and all the php experts out there!!!

I need some help with this statement which I read in a php code sample...

From what I know, print prints what is in the parentheses " and ".

The confusing part is the .( and the ).

Do the .( and ). tell php that what is inside has to be evaluated ( ie as an expression )???

It seems that its somethng like this...

"print without evaluating here" .(evaluatethecodeandprintoutput)."continue printing without evaluating as xpression"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Dec 10th, 2003, 07:47
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, PHP is capable of printing variables from within strings and from without, namely because it uses the dollar sign to denote them. But if you were to print the whole statement:

print "$counter times 2 is ($counter*2)
"

in PHP without leaving ($counter*2) outside of the quotes, then you would print:

3 times 2 is 3*2

(for example)

Thus, ($counter*2) needs to be done seperately. But when it is evaluated, you want it to be part of the string you are printing. Thus you need to concatenate your values into one string. The full stop (or period) sign is PHP's concatenation operator. In most other languages it is + or & or something similiar. PHP distinguishes between addition + and concatenation . quite nicely.

So, to summarise (!):

print "$counter times 2 is ".($counter*2)."
"

prints, $counter times 2 is (the result of ($counter*2) added to the string)


Hope this clears that up!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Dec 10th, 2003, 08:05
Reputable Member
Join Date: Aug 2003
Location: Singapore
Posts: 321
Thanks: 0
Thanked 0 Times in 0 Posts
Yes! Thanks . That cleared pretty much everything except the bracket ( or the parentheses ).. Anything that is inside a bracket is to be calculated??? Actually, I've heard of the concatenation operator somewhere but didn't bother to read further
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Dec 10th, 2003, 09:22
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, anything inside a bracket is done first. In this case, the bracket is used partly for that and also because they are both numbers. The bracket lets PHP know that, if the two are of the same type, then it can carry out an operation, in this case, addition.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old Dec 10th, 2003, 09:56
Rob's Avatar
Rob Rob is online now
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,154
Blog Entries: 7
Thanks: 26
Thanked 18 Times in 15 Posts
you mean multiplication?
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #6  
Old Dec 10th, 2003, 10:12
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Errrm, yes. Sorry!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #7  
Old Dec 10th, 2003, 10:50
Reputable Member
Join Date: Aug 2003
Location: Singapore
Posts: 321
Thanks: 0
Thanked 0 Times in 0 Posts
thanks a lot sirkent! here's your shrine!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Tags
print, counter, times, counter2ltbrgt

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Age Counter acrikey JavaScript Forum 4 Jun 2nd, 2008 12:37
Counter confused Website Planning 6 May 21st, 2007 03:27
ID Counter problems mikka23 PHP Forum 1 Nov 20th, 2006 06:07
hit counter? skyfire400 Web Page Design 6 Mar 7th, 2006 14:00
A PHP web counter? k3nshin PHP Forum 19 Feb 19th, 2004 22:35


All times are GMT. The time now is 14:39.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42