Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Array initialization

There are lot of different ways how to initialize array in php. Which one is the best? which is the slowest?

Here are some test results:

<?php
//average result: 0.0044 seconds.
for ($i=0;$i<1001;$i++)
{
    $a=array("1","2","3","4","5","6","7");
}  

//average result: 0.0021 seconds
for ($i=0;$i<1001;$i++)
{
    $a[0]="1";
    $a[1]="2";
    $a[2]="3";
    $a[3]="4";
    $a[4]="5";
    $a[5]="6";
    $a[6]="7";
}  

//average result: 0.0046 seconds
for ($i=0;$i<1001;$i++)
{
    $a[]="1";
    $a[]="2";
    $a[]="3";
    $a[]="4";
    $a[]="5";
    $a[]="6";
    $a[]="7";
}  

//average result: 0.0049 seconds
for ($i=0;$i<1001;$i++)
{
    $a = range(1, 7);
}     

?>

You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus