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
>com
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)
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 m
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
oops, yes of course lol
Tim-Hinnerk Heuer
http://www.ihostnz.com
On Tue, Dec 23, 2008 at 7:43 PM, Lars Torben Wilson wrote:
> 2008/12/22 German Geek :
> > agree, ++$i wont save u nething, it just means that the variable is
> > incremented after it is used:
>
> You meant ". . .before it is used:
On Mon, Dec 22, 2008 at 11:43 PM, Lars Torben Wilson
wrote:
> 2008/12/22 German Geek :
> > 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 individual who likes to optim
2008/12/22 German Geek :
> 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;
>
> wi
2008/12/22 Nathan Nobbe :
> On Mon, Dec 22, 2008 at 3:10 PM, Clancy 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
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 Nob
On Mon, Dec 22, 2008 at 3:10 PM, Clancy 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 us.
>
> Schlossnag
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
MikeP schreef:
> Hello,
> I am trying to output the value of the following:($x is an int incremented
> by a for statement.
> echo "
>
>'$users[$x][U]'
> ";
>
> I have tried putting the quotes all over and all I get is:
> 'Array[U]'.
>
> What am I doing wrong.
you need to help p
2008/12/21 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";
>
> ha
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 rea
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 seco
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
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
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,
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 yo
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 wrote:
> MikeP schrieb:
>
>> I have tried putting the quotes all over and all I get is:
>> 'Array[U]'.
>>
>>
>>
> Try to avoid accessing the two-dimens
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
http://www.ihost
$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 "
'" . $users[$x]['U'] ."'
";
Tim-Hinnerk Heuer
http://www.
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 '', $users[$x]['U'], '';
Or by concating the string with the .-Operator:
23 matches
Mail list logo