So I'm currently working on a PHP project. Now I'm trying to build an Array I want to output later on. The Array should only be filled with Value when the if-condition is true.
I cant seem to find any working code or any help. I don't really know what to try next.
$maxTestDuration = 20;
$startTime = strtotime("now");
$endTime = strtotime("+1 hour");
$testDuration = $endTime - $startTime;
$currentTest = "Test1";
$test2 = "test2";
$test3 = "test3";
$test4 = "test4";
$testDuration2 = "300";
$testDuration3 = "10";
$testDuration4 = "5420";
if ($testDuration > $maxTestDuration)
{
$overTimeTests =
[
$currentTest => $testDuration,
"test2" => "300",
"test3" => "2000",
"test4" => "5420",
];
}
foreach ($overTimeTests as $testName => $testDuration)
{
$testText = $testName.": ".$testDuration." seconds
";
echo $testText;
}
The Result should be an Output of just the three tests that run under 20 seconds. Instead, it shows all four tests. I also tried changing $endTime
so that test1 would be faster than 20 seconds but then I get errors, that the array is empty.