I was told that in C++, it's best to use minimal output (cout) statements....

Is it the same way in php? For example, does it matter which of the following ways I use?

print ("1st sentence. ");
print ("2nd sentence. ");
print ("3rd sentence. ");
print ("4th sentence.");

OR

print ("1st sentence. 2nd sentence. 3rd sentence. 4th sentence.");

Now, obviously, it's easier to use the second example, but when I get into complex and long print statements, I like to break things up for readability and such. Does it make that much of a difference to use the print statement four times instead of one?

    I am not away of any performance issues caused by the number of echo or print calls in php.

      yes you should minimize print statements, they are not destructuve, and those who program in php anyway (as its a scripting language, and they are just making webpages) tend to do much worse things to their program than use to many prints.

      however if you are really interested in streamlining your code spead. perhaps for a contest of some kind use 'echo'

      http://www.php.net/manual/en/function.echo.php

      echo is identical to print except that echo returns nothing, while print returns a boolean, so php must now load another boolena into memory and return it.

      the speed is so insignificant that you can even forget i said anthing about it. and if you even get to point where your php code is bottlenecking on print statements you are either doing something seriously wrong, or the rest of your code must be better than anything i can imagine.

        The good thing about PHP is that if you have a long bunch of static output, you can just put it outside the <?php ... ?> tags.

          Originally posted by bad_goose
          The good thing about PHP is that if you have a long bunch of static output, you can just put it outside the <?php ... ?> tags.

          I agree in the fullest. I have recently taking to putting only the absolute minimum inside php tags. Now I will do things like the following. This is not a real life example, but its an idea of what I have taken to doing. I guess it's just a clean way to do it. Also, when changing the appearance of the HTML output, it's easier working with the raw html and moving variable echos around rather than messing with stuff in print() commands and having to delimit stuff with slashes.

          <table blah><tr>
          <?
          while($foo = mysql_fetch_array($result, MYSQL_ASSOC))
          { // loop while there are results ?>

          <td>You're username is <? echo $foo["name"]; ?>. Thanks for logging in.</td>

          <? } // end while ?>

          </tr></table>

            you can use printf() like in c

            printf("%d %d %d %d"a,b,c,d);
            
              Write a Reply...