- microtime: documentation ( source)
- compact: documentation ( source)
<?php
$startTime = microtime(true);
for($i=0; $i<100000; $i++) {
$foo = "foo";
$bar = "bar";
$baz = "baz";
$array = compact('foo','bar','baz');
}
$endTime = microtime(true);
$elapsed = $endTime - $startTime;
echo "With compact : $elapsed seconds\n";
$startTime = microtime(true);
for($i=0; $i<100000; $i++) {
$array = [
'foo' => 'foo',
'bar' => 'bar',
'baz' => 'baz'
];
}
$endTime = microtime(true);
$elapsed = $endTime - $startTime;
echo "Without compact time : $elapsed seconds\n";