I should echo
a table with 1000 rows of data, can I echo
all the data in one string or is it better to echo
a row per time?
They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print .
Echo vs Print Echo can be used in expressions as it has no return value while print has a return value of 1. echo is marginally faster than print and can take multiple parameters while print can take only one argument.
php echo directly in the browser. If you directly view backend. php in your browser you will see the echo in the same way as index. php.
According to http://phplens.com/lens/php-book/optimizing-debugging-php.php (see last third of article) you should use one big echo statement, and use single quotes instead of double quotes, so PHP hasn´t to check for variables within the string.
simple test for support:
$bgn = microtime(true);
for ($i=0; $i<=1000; $i++)
{
echo $i;
}
echo "\n", round(microtime(true)-$bgn, 4), "\n";
unset($bgn);
$bgn = microtime(true);
$b = '';
for ($i=0; $i<=1000; $i++)
{
$b.=$i;
}
echo $b;
echo "\n", round(microtime(true)-$bgn, 4), "\n";
?>
First run return 0.0022
, while second run return 0.0007
... however this is small set of data, memory usage is quite small.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With