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.
     
    vinodxx, Sep 24, 2008 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    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