- microtime: documentation ( source)
- error_reporting: documentation ( source)
- in_array: documentation ( source)
<?php
error_reporting(0);
$start = microtime(true);
for($i = 0; $i < 100000; $i++) {
$alreadyOutput = array();
foreach ($results as $result) {
if(in_array($result->date, $alreadyOutput)){
continue;
}
$alreadyOutput[] = $result->date;
echo $result->date . "<br />";
}
}
echo "in_array: ".(microtime(true) - $start)."ms || ";
$start2 = microtime(true);
for($i = 0; $i < 100000; $i++) {
$echoedArray = array();
foreach ($results as $result) {
if ($echoedArray[$result->date]) {
continue;
}
echo $result->date . "<br />";
$echoedArray[$result->date] = true;
}
}
echo "by key: ".(microtime(true) - $start2)."ms";