1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help:Minor doubt on concatenating strings

Discussion in 'PHP' started by vinodxx, Sep 24, 2008.

  1. #1
    I have written a PHP function like this.
    <?php
    function add($x,$y)
    {

    echo $x." + ".$y." = ";
    echo $x+$y."<br />";
    }

    echo add(12,13);
    echo add(121,131);
    ?>

    result:
    -----------------
    12 + 13 = 25
    121 + 131 = 252
    ----------------

    Now If I change the above function like this

    function add($x,$y)
    {
    echo $x." + ".$y." = ".$x+$y."<br />";
    }

    result:
    -------------------
    25
    252
    ------------------

    Why it is $x." + ".$y." = " part has no effect.

    I tried on a WAMP server localhost.
    SEMrush
     
    vinodxx, Sep 24, 2008 IP
    SEMrush
  2. ads2help

    ads2help Peon

    Messages:
    2,148
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    function add($x,$y)
    {
    echo $x." + ".$y." = ".($x+$y)."<br />";
    }
    PHP:
    there must be a bracket whenever addition/subtraction/(mathematical functions Maybe) is used.
     
    ads2help, Sep 24, 2008 IP