[PHP] Re: Assignment (Was Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-24 Thread tedd
At 11:06 AM +1100 12/24/08, Clancy wrote: On Tue, 23 Dec 2008 10:25:13 -0500, tedd.sperl...@gmail.com (tedd) wrote: Two things: 1. One statement, one line. 2. The code between the two examples is different; produces different results; and thus is rather pointless in making a definitive

Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-23 Thread German Geek
oops, yes of course lol Tim-Hinnerk Heuer http://www.ihostnz.com On Tue, Dec 23, 2008 at 7:43 PM, Lars Torben Wilson larstor...@gmail.comwrote: 2008/12/22 German Geek geek...@gmail.com: agree, ++$i wont save u nething, it just means that the variable is incremented after it is used: You

Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-23 Thread Clancy
On Mon, 22 Dec 2008 22:40:58 -0800, larstor...@gmail.com (Lars Torben Wilson) wrote: Well, in all fairness, it *is* faster--but you'll only notice the difference in extremely tight and long-running loops (try it ;) ). As long as you know why you're using it and what the side effects are, it

[PHP] Assignment (Was Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-23 Thread tedd
At 9:10 AM +1100 12/23/08, Clancy wrote: Schlossnagle (in Advanced PHP Programming) advises: $i = 0; while ($i $j) { ++$i; } rather than: $i = 0; while ($i $j) { ... $i++; } as the former apparently uses less

[PHP] Re: Assignment (Was Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-23 Thread Clancy
On Tue, 23 Dec 2008 10:25:13 -0500, tedd.sperl...@gmail.com (tedd) wrote: At 9:10 AM +1100 12/23/08, Clancy wrote: Schlossnagle (in Advanced PHP Programming) advises: $i = 0; while ($i $j) { ++$i; } rather than: $i = 0; while ($i $j) { ...

Re: [PHP] Variable as an index

2008-12-22 Thread Jochem Maas
MikeP schreef: Hello, I am trying to output the value of the following:($x is an int incremented by a for statement. echo tr td width='110' bgcolor='$row_color' nowrap '$users[$x][U]'/td /tr; I have tried putting the quotes all over and all I get is: 'Array[U]'. What

[PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-22 Thread Clancy
On Mon, 22 Dec 2008 10:20:09 +1100, dmag...@gmail.com (Chris) wrote: I'd call this a micro-optimization. If changing this causes that much of a difference in your script, wow - you're way ahead of the rest of us. Schlossnagle (in Advanced PHP Programming) advises: $i = 0; while ($i

Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-22 Thread Nathan Nobbe
On Mon, Dec 22, 2008 at 3:10 PM, Clancy clanc...@cybec.com.au wrote: On Mon, 22 Dec 2008 10:20:09 +1100, dmag...@gmail.com (Chris) wrote: I'd call this a micro-optimization. If changing this causes that much of a difference in your script, wow - you're way ahead of the rest of

Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-22 Thread German Geek
agree, ++$i wont save u nething, it just means that the variable is incremented after it is used: $i = 0; while ($i 4) echo $i++; will output 0123 while $i = 0; while ($i 4) echo ++$i; will output 1234 Tim-Hinnerk Heuer http://www.ihostnz.com On Tue, Dec 23, 2008 at 7:25 PM, Nathan

Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-22 Thread Lars Torben Wilson
2008/12/22 Nathan Nobbe quickshif...@gmail.com: On Mon, Dec 22, 2008 at 3:10 PM, Clancy clanc...@cybec.com.au wrote: On Mon, 22 Dec 2008 10:20:09 +1100, dmag...@gmail.com (Chris) wrote: I'd call this a micro-optimization. If changing this causes that much of a difference in your

Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-22 Thread Lars Torben Wilson
2008/12/22 German Geek geek...@gmail.com: agree, ++$i wont save u nething, it just means that the variable is incremented after it is used: You meant . . .before it is used:, right? Torben $i = 0; while ($i 4) echo $i++; will output 0123 while $i = 0; while ($i 4) echo ++$i;

Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-22 Thread Nathan Nobbe
On Mon, Dec 22, 2008 at 11:43 PM, Lars Torben Wilson larstor...@gmail.comwrote: 2008/12/22 German Geek geek...@gmail.com: agree, ++$i wont save u nething, it just means that the variable is incremented after it is used: You meant . . .before it is used:, right? i hope so, coming from an

[PHP] Variable as an index

2008-12-21 Thread MikeP
Hello, I am trying to output the value of the following:($x is an int incremented by a for statement. echo tr td width='110' bgcolor='$row_color' nowrap '$users[$x][U]'/td /tr; I have tried putting the quotes all over and all I get is: 'Array[U]'. What am I doing wrong. Thanks

Re: [PHP] Variable as an index

2008-12-21 Thread Marc Steinert
MikeP schrieb: I have tried putting the quotes all over and all I get is: 'Array[U]'. Try to avoid accessing the two-dimensional array $users inside a string. Use echo's ability to accept multiple parameters: echo 'trtd.', $users[$x]['U'], '/td'; Or by concating the string with

Re: [PHP] Variable as an index

2008-12-21 Thread German Geek
$users is an array and you are trying to simply put it in a string. $x seems to be undefined ergo it's not printing anything. If 'U' is the index in the array for your variable, use the '.' operator to concatenate strings: echo tr td width='110' bgcolor='$row_color' nowrap ' .

Re: [PHP] Variable as an index

2008-12-21 Thread German Geek
OK. I would think it uses more memory then, but doubt it would be slower. Isnt the output buffered in memory anyway though in PHP? Surely the buffer is bigger than 100 bytes (which is about the length of this string). So one way or the other, the memory is used. Tim-Hinnerk Heuer

Re: [PHP] Variable as an index

2008-12-21 Thread German Geek
Why is the first method faster and uses less memory? Tim-Hinnerk Heuer http://www.ihostnz.com On Mon, Dec 22, 2008 at 10:59 AM, Marc Steinert li...@bithub.net wrote: MikeP schrieb: I have tried putting the quotes all over and all I get is: 'Array[U]'. Try to avoid accessing the

Re: [PHP] Variable as an index

2008-12-21 Thread Marc Steinert
German Geek schrieb: Why is the first method faster and uses less memory? Because the concatenation operator first reassembles a new string, stores it in memory then passes this newly created string to the echo function, if I'm not misstaken. -- http://bithub.net/ Synchronize and share

Re: [PHP] Variable as an index

2008-12-21 Thread Anthony Gentile
for e.g. $var = 'world'; echo hello $var; vs echo 'hello '.$var; The first uses twice as many opcodes as compared to the second. The first is init a string and adding to it the first part(string) and then the second part (var); once completed it can echo it out. The second is simply two opcodes,

Re: [PHP] Variable as an index

2008-12-21 Thread Anthony Gentile
True, it might mean the very slightest in milliseconds...depending on what you're doing/hardware. However, no harm in understanding the difference/how it works. Many will code echo Hello World and echo 'Hello World'; and never know the difference, I just happen to think being aware of the details

Re: [PHP] Variable as an index

2008-12-21 Thread Chris
Anthony Gentile wrote: True, it might mean the very slightest in milliseconds...depending on what you're doing/hardware. Connecting to a db will (probably) take longer than most of those differences, let alone running a query processing the results. Ternaries that make a lot of people feel

Re: [PHP] Variable as an index

2008-12-21 Thread Chris
Anthony Gentile wrote: for e.g. $var = 'world'; echo hello $var; vs echo 'hello '.$var; The first uses twice as many opcodes as compared to the second. The first is init a string and adding to it the first part(string) and then the second part (var); once completed it can echo it out. The

Re: [PHP] Variable as an index

2008-12-21 Thread German Geek
Yes, i agree with this. Even if it takes a few nano seconds more to write out more understandable code, it's worth doing it because code management is more important than sqeezing out the last nano second. And then also an $var = Hello; echo $val World; has less characters than and is more

Re: [PHP] Variable as an index

2008-12-21 Thread Lars Torben Wilson
2008/12/21 German Geek geek...@gmail.com: Yes, i agree with this. Even if it takes a few nano seconds more to write out more understandable code, it's worth doing it because code management is more important than sqeezing out the last nano second. And then also an $var = Hello; echo $val