Variable assignment and Echo Statement

Discussion in 'PHP' started by krishmk, May 28, 2010.

  1. #1
    I recently came across a script file. The coder had given variable assignment and echo statement on the same line. Is this a good coding practice? and does it have any benefit?

    <?php
    echo $num = 500;
    ?>
    PHP:
    Appreciate your feeback...
     
    krishmk, May 28, 2010 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    simply it saves one line

    you can allways do it in two lines

    Regards

    Alex
     
    kmap, May 28, 2010 IP
  3. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #3
    You can also write as
    But occupies some space in 100k lines program so advanced coders will write as
     
    roopajyothi, May 28, 2010 IP