View Single Post
  #9 (permalink)  
Old 08-08-2007, 08:55 AM
kathir kathir is offline
D-Web Trainee
 
Join Date: Feb 2007
Posts: 25
kathir is on a distinguished road
Default Re: Site Performance - Tips & Tricks

Hi Vijayanand,

From your suggestion, we can directly use “echo” instead of concat the strings.
But we need to consider one thing; “echo” is an expensive I/O function it takes more time to compare with other PHP functions.

Consider this ex:
<?php
$vTemp = 10;
For($vLIndex = 0; $vLIndex < $vTemp; $vLIndex++) {
echo '<option>', $vLIndex,'</option>';
}
?>

From above code “echo” statement executed by 10 times within the loop it will automatically increase the execution time. Now consider bellow code.

<?php
$vTemp = 10;
$ArrOptions = array();
For($vLIndex = 0; $vLIndex < $vTemp; $vLIndex++) {
$ArrOptions[] = '<option>'.$vLIndex.'</option>';
}
?>
echo implode(‘’, $ArrOptions);

From above code not concat any string and do not uses “echo” within the loop. Instead of “echo” we use array functions. Basically array functions faster then string functions. And finally prints all array element by a single “echo” with help of implode function.

Thanks
- Kathir
Reply With Quote