Re: Variable as an index

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> 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@xxxxxxxxxx> 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
> >
> >
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux