Login Register


[Need Help] PHP runsum formula filter_list
Author
Message
RE: [Need Help] PHP runsum formula #11
(04-16-2014, 01:53 AM)0xDEAD10CC Wrote: It doesn't bother me, I'm just informing you on things that could improve your code. You didn't understand me the first time if you thought I was implying that it only pertained to arrays...

Since OP still hasn't responded to his own thread, I don't know how he expects us to help him though.


Well you taught me something new, so this thread wasn't a total waste.
Thanks for that Smile
Ill rep you.
[Image: screenshot_108.png]

Reply

RE: [Need Help] PHP runsum formula #12
(04-15-2014, 03:06 PM)0xDEAD10CC Wrote: Its good to surround the variables with {} to allow them to be parsed easier within double quotted strings. Theres other reasons for arrays too.

Interpolation doesn't change how a variable is parsed, but rather makes it easier on the eyes, or acts as a delimiter for data subsequent to the interpolated variable.

PHP Code:
$x = 'x'; echo "{$x}xx";

In fact, interpolation is very moderately slower than concatenation.

PHP Code:
echo 'Your employees have worked ' . $hours . ' hours.';

Another faster alternative is to echo the data seperately.

PHP Code:
echo 'Your employees have worked ', $hours, ' hours.';

Just thought I'd share that useful bit of information.

Reply

RE: [Need Help] PHP runsum formula #13
(05-30-2014, 05:52 AM)haqqur Wrote: Interpolation doesn't change how a variable is parsed, but rather makes it easier on the eyes, or acts as a delimiter for data subsequent to the interpolated variable.

Do you know what you're talking about?
PHP Code:
<?php $x = array('1' => 'one', '2' => 'two', '3' => 'three'); echo "$x['1']"; // error echo "{$x['1']}"; // no error ?>

And my main point was not on speed over concatenation, but readability. Still, you're arguing concatenation against variable interpolation which is absolutely senseless because there are cases where either or, may be faster or slower, depending on how many concatenations are required.

And interpolation from my tests does prove to be slightly faster with braces, as the same with the results in this thread on SO: http://stackoverflow.com/questions/13620...on-in-php5.

Here is a nice article as well http://nikic.github.io/2012/01/09/Dispro...-Myth.html

Plus there is this case:
PHP Code:
<?php $x = 'P'; echo "$xear"; // invalid echo "{$x}ear"; // good ?>

Reply







Users browsing this thread: 1 Guest(s)