<?php
$array = array_fill(0,50000,'TEST DATA');
$arraykeyexists_result = array();
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
if (array_key_exists($i,$array)) {
$arraykeyexists_result[] = 1;
}
else {
$arraykeyexists_result[] = 0;
}
}
$arrtime = round(microtime(true)-$start,3);
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
if (isset($array[$i]) || $array[$i] === null) {
$arraykeyexists_result[] = 1;
}
else {
$arraykeyexists_result[] = 0;
}
}
$istime = round(microtime(true)-$start,3);
$totaltime = $arrtime+$istime;
$arrpercentage = round(100*$arrtime/$totaltime,3);
$ispercentage = round(100*$istime/$totaltime,3);
echo "array_key_exists(): $arrtime [$arrpercentage%] seconds\n";
echo "isset(): $istime [$ispercentage%] seconds\n";
?>