Both work, but which is best...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike

    Both work, but which is best...

    Newbie here. Both of these seem to work fine, but is there any reason why
    one is better than the other?

    $myvar = "cheese";

    $biscuits = "I just love $myvar biscuits";
    or
    $biscuits = "I just love" . $myvar . "biscuits";

    print($biscuits );


  • Pedro Graca

    #2
    Re: Both work, but which is best...

    mike wrote:[color=blue]
    > Newbie here. Both of these seem to work fine, but is there any reason why
    > one is better than the other?
    >
    > $myvar = "cheese";
    >
    > $biscuits = "I just love $myvar biscuits";
    > or
    > $biscuits = "I just love" . $myvar . "biscuits";
    >
    > print($biscuits );[/color]

    They're not exactly equal (*) ...


    Just use the one you like the best.
    The difference isn't noticeable.

    .... you missed one other way to do it:

    $biscuits = 'I just love ' . $myvar . ' biscuits';


    The differences in speed between all of these are nothing compared to
    how easy/hard you'll find understanding and changing the code later.


    (*)
    first ==> I just love cheese biscuits
    second ==> I just lovecheesebiscu its

    --
    USENET would be a better place if everybody read: : mail address :
    http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
    http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
    http://www.expita.com/nomime.html : to 10K bytes :

    Comment

    Working...