<?php
$arrX = array(2, 4, 6, 8, 10, 12, 14, 16, 18, 20);
$arrY = array(1, 3, 5, 7, 9, 11, 13, 15, 17, 19);
$iter = 100000;
$start = microtime(true);
$number_p = 3.14;
$distance = 40 / 5;
$total = 0;
$cntX = count($arrX);
$cntY = count($arrY);
$var0 = $number_p * $distance;
for ($a = 0; $a < $iter; $a++) {
$varA = $number_p + $a;
foreach ($arrX as $i => $x) {
$varB = $x * $varA;
foreach ($arrY as $j => $y) {
$value = $varB * ($y + $var0);
$total += $value;
switch ($i) {
case 3:
$total += 100;
break;
case 6:
$total += 500;
break;
case 9:
$total += 1000;
break;
}
if ($value % 2 == 0) {
$total = $total + 1;
} else {
$total = $total + 2;
}
}
}
}
echo "Total: $total";
$time = microtime(true) - $start;
echo "<br>Script time is $time";