<?php
$vars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');
$start = microtime(true);
for($k=0;$k<100;$k++) {
$str = ltrim(strrev(chunk_split(implode(array_reverse($vars)), 3, ';')),';');
}
$end = microtime(true);
echo $end - $start;
echo "\n\n";
$start = microtime(true);
for($k=0;$k<100;$k++) {
$size = sizeOf($vars);
for ($i = $size-3; $i > 0; $i-=3) {
array_splice($vars,$i,0,";");
}
}
$end = microtime(true);
echo $end - $start;
echo "\n\n";
$start = microtime(true);
for($k=0;$k<100;$k++) {
$array = array_reverse(range('a', 'h')); // reverse
$array = array_chunk($array, 3); // cut by threes
$string = '';
foreach ($array as $value) {
$string .= implode($value); // glue them
if(count($value) == 3) { // if still three, add a semi
$string .= ';';
}
}
$string = strrev($string); // then reverse them again
}
$end = microtime(true);
echo $end - $start;
preferences:
38.89 ms | 402 KiB | 5 Q