- microtime: documentation ( source)
- round: documentation ( source)
- array_shift: documentation ( source)
<?php
for ($a = 0; $a < 5; $a++) {
$start = microtime(true);
for ($i = 0; $i < 10000; $i++) {
$args = ['a', 'b'];
foreach ($args as $arg) {
$arg = (string)$arg;
}
}
echo round(microtime(true) - $start, 5) . PHP_EOL;
$start = microtime(true);
for ($i = 0; $i < 10000; $i++) {
$args = ['a', 'b'];
while (count($args)) {
$arg = (string)array_shift($args);
}
}
echo round(microtime(true) - $start, 5) . PHP_EOL;
}