First, I want to say that I am not good at JavaScript. Therefore, if this is not so, please do not let me into oblivion.
JavaScript:
var time = ["1270690925", "1270696925", "1273696925"]; var spaceTime = 60 * 30; for (var i in time) { for (var j in time) { if (time[i] - time[j] < spaceTime) alert("You must put a greater length between these two times: " + time[i] + " and " + time[j] + "."); } }
Based on this PHP code:
function timeCheck($timeArrays = array(), $spaceTime = 1800) { foreach ($timeArray as $time1) { foreach ($timeArray as $time2) { if ($time1 - $time < $spaceTime) {
Attempt No. 2 (after viewing comments) in PHP:
function timeCheck($times = array(), $interval = 1800) { sort($times); for ($i = 0, $j = 1, $k = count($times); $j < $k; ++$i, ++$j) { if (($times[$j] - $times[$i]) < $interval) { echo "{$times[$i]} is less then $interval away from {$times[$j]}." . PHP_EOL; } } }
source share