- microtime: documentation ( source)
<?php
class Collection
{
private $a = array();
public function __construct()
{
for ($i = 0; $i < 100000; $i++) {
$this->a[] = $i;
}
}
public function all()
{
return $this->a;
}
}
$coll = new Collection();
$start = microtime(true);
foreach ($coll->all() as $k => $v) {
$a[$k] = $v + 1;
}
echo "Completed in ", microtime(true) - $start, " Seconds\n";
$start = microtime(true);
$arr = $coll->all();
foreach ($arr as $k => &$v) {
$v = $v + 1;
}
echo "Completed in ", microtime(true) - $start, " Seconds\n";