Re: Variable as an index
| From: | Anthony Gentile | Date: | Sun, 21 Dec 2008 23:05:21 +0000 |
| Subject: | Re: Variable as an index | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-284941@lists.php.net to get a copy of this message | ||
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, a concatenate and an echo. Interpolation.
Anthony Gentile
On Sun, Dec 21, 2008 at 5:47 PM, German Geek <geek.de@gmail.com> wrote:
> 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.ihostnz.com
>
>
> On Mon, Dec 22, 2008 at 11:12 AM, Marc Steinert <lists@bithub.net> wrote:
>
> > 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 your files over the web for free
> >
> >
>