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.
|
|
|
|
|
![]() |
||
print "$counter times 2 is ".($counter*2)."<br>"
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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" |
|
|
|
|||
|
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! |
|
|||
|
Yes! Thanks
|
|
|||
|
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.
|
|
||||
|
you mean multiplication?
__________________
Rob - SEO Specialist Owner & Founder of Webforumz.com I am currently unavailable for private work
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
|
|||
|
Errrm, yes. Sorry!
|
![]() |
| Tags |
| print, counter, times, counter2ltbrgt |
| Thread Tools | |
|
|
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 |