I've been introduced with range() function not so long ago, and I found that examples about it is somewhat wrong, even inefficient:
<?php
$o = "";
$time_start = microtime(true);
foreach(range(1, 10000) as $val) {
$o .= $val;
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo 'rangein: '.$time.'<br />';
$o = "";
$time_start = microtime(true);
$a = range(1, 10000);
foreach($a as $val) {
$o .= $val;
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo 'rangeout: '.$time.'<br />';
?>
Which gives results:
rangein: 0.0025348663330078
rangeout: 0.0019199848175049
In some cases difference is even bigger and proportional to the range generated. I suppose that results of range() are cached/hashed.
Note: execution order does affects execution times, but difference still exists