Results 1 to 5 of 5

Thread: help, I've got a hard time of understanding this one....

  1. #1
    Join Date
    May 2009
    Posts
    62
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Default help, I've got a hard time of understanding this one....

    what is the difference between these two ECHO statements:

    $test = "30cm";
    $newtest = $test + "40cm";

    //first echo version
    echo "Your imaginary box has a width of $newtest centimeters";

    //second echo version
    echo "your imaginary box has a width of " . $newtest . " centimeters";

    OUTPUT:
    Your imaginary box has a width of 70 centimetersYour imaginary box has a width of 70 centimeters

    it seems like their output is the same..... but when I added "cm" in the first echo version:

    //fist echo version
    echo "Your imaginary box has a width of $newtestcm centimeters";

    this is what the browser displayed:

    OUTPUT:
    Your imaginary box has a width of centimetersyour imaginary box has a width of 70 centimeters



    The number 70 was not displayed....I don't understand it... Also, the statement of the first version of echo, I write it in a manner that it is executed as one string, so I expected that instead of printing 70, it will print $newtest, but it doesn't seem to be that way...... Can somebody explain to me this?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    One this line:

    Code:
    echo "Your imaginary box has a width of $newtestcm centimeters";
    the variable $newtestcm is not defined.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    heavensgate15 (06-01-2009)

  4. #3
    Join Date
    May 2009
    Posts
    62
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Default Thanks...

    I also think about that... but what bothers me is that, is it possible to echo multiple characters together with a variable in just one string quote? what I mean is this:

    echo "Your imaginary box has a width of $test centimeters";



    What if I wanted to display $test as a string, not a variable:

    OUTPUT:
    your imaginary box has a width of $test centimeters

  5. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    use single quotes then. PHP 101:

    The following code:

    Code:
    $str = 'TEST';
    echo "This is a $str";
    will output:

    Code:
    This is a TEST
    where as this:

    Code:
    $str = 'TEST';
    echo 'This is a $str';
    will output:

    Code:
    This is a $str
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. The Following User Says Thank You to thetestingsite For This Useful Post:

    heavensgate15 (06-01-2009)

  7. #5
    Join Date
    May 2009
    Posts
    62
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Default

    Thanks, you really help a lot......

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •