Fatal error: Maximum execution time of 120 seconds exceeded

Good day everyone, I'm trying . This is the code which demonstrates what I'm doing:

 <?php
$NoOfGames = 10;
$time = array("06:00:00 " => "07:00:00", "07:00:00" => "08:00:00", "08:00:00" => "09:00:00", "09:00:00" => "10:00:00", "10:00:00" => "11:00:00", "11:00:00" => "12:00:00","12:00:00" => "13:00:00","13:00:00" => "14:00:00","14:00:00" => "15:00:00","15:00:00" => "16:00:00","16:00:00" => "17:00:00","17:00:00" => "18:00:00");

for($i=0;$i<$NoOfGames;$i+1){
    $start_time = array_rand($time);
    $end_time = $time[$start_time];
    $time_new[$start_time] = $end_time;
}
$i =1;
foreach($time_new as $start => $end)
{

    echo  $i. ") ". $start . " to ".  $end . "<br>";
    $i++;
}
?>

However, this outputs it keeps showing this fatal error message

and I want to display it like this instead

1) 17:00:00 to 18:00:00
2) 06:00:00 to 07:00:00
3) 12:00:00 to 13:00:00
4) 11:00:00 to 12:00:00
5) 16:00:00 to 17:00:00
6) 08:00:00 to 09:00:00
7) 13:00:00 to 14:00:00
8) 15:00:00 to 16:00:00
9) 14:00:00 to 15:00:00
10) 09:00:00 to 10:00:00

Upvotes: 0

Views: 4831

Answers (1)

Chris Lear
Chris Lear

Reputation: 6742

This should work:

Change $i+1 to $i++

The reason is that $i+1 just evaluates to 1 every time (ie doesn't actually increment $i), meaning the loop never exits.

Upvotes: 3

Related Questions