0

I have a array with time ranges, the time range has specific video, i m going to show video which matched with current time

i created a variables like below, and assigned to array, anyone please help me for filter video for current time from array

ex- if the server time is 2012-06-08 14:45:10 this i need show video 2

$d1 = "2012-06-08 14:26:39";
$video1='http://video-js.zencoder.com/oceans-clip.mp4';
$d2 = "2012-06-08 14:39:39";
$video2='http://video-js.zencoder.com/oceans-clip.mp4';
$d3 = "2012-06-08 14:56:10";

$cc=array(
1=>array($d,$d2,$video1),
2=>array($d2,$d3,$video2)
);

//get current time
$ctime=date('Y-m-d H:i:s',time());
//need to check matched array element for current time within above array date ranges
//Ex - if the server time is  2012-06-08 14:45:10 this need show video 2
0

2 Answers 2

1

You can try this

$showvideo = "";
for ($i = 1; $i <= sizeof($cc); $i++) {
    $video = $cc[$i];
    if ($ctime >= $video[0] && $ctime <= $video[1]) {
        $showvideo = $video[2];
        break;
    }
}

if ($showvideo == "") {
    // Error
}

Basically PHP allows you to compare dates so just go through array and compare each to see if the date you has is between the two.

Sign up to request clarification or add additional context in comments.

2 Comments

Er excuse my use of foreach, I think I used it wrong, let me correct it, I'm really rusty on PHP and code in Python these days.
Haha yeah sorry :( I really forgot PHP syntax o.o But glad the logic got through :) Cheers [Edit: Okay now I think I corrected the syntax to work with what you presented XD Sorry about that haha]
1

Your going to need to assign each video to have a range of time, and then you can look for the correct video based on your time input

for example

$ctime=date('Y-m-d H:i:s',time());

$video1=array("http://video-js.zencoder.com/oceans-clip.mp4","2012-06-08 14:26:39","2012-06-08 14:39:39")

if ($ctime >= $video1[2]) && ($ctime <= $video1[3]) { echo $video1[1]; }

I believe this should solve your problem

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.