views:

91

answers:

2

Right now im running something based on time and including files. This is a long file and seems unnecessary. What I want to do is auto increment the times for the 24 times i call code.

current style coding:

if($time >= "0000" && $time < "0100") { include("1.php"); } elseif($time >= "0200" && $time < "0300") { include("2.php");

Is there a way to assign an automatic array to each instance of the numbers something like this and loop it 24 times to make it fast loading and simple to code?

if($time >= "$times" && $time < "$times2") { include("$hours.php");

A: 

Strip the last 2 chars off your timecode, turn it into an integer, and build your include from that?

$index=intval(substr($time,0,-2));
$index=max(1, $index);
include("$index.php");

Or convert to a decical value and take its ceiling?

$index=ceil(intval($time)/100);
$index=max(1, $index);
include("$index.php");
Paul Dixon
+1  A: 
$num = ceil($time / 100);
include "$num.php";
cletus
This worked perfectly, thanks.