UPDATE
finnaly, i solve my problem..
can someone remove the duplicate tags from my question and find the correct title for this issue? maybe someone who have same issue like me, can search my question and find the answer..
sorry for my english, i still learning..
// this is variable from mysql database
$mysql_start = "2018-12-28 21:45:00"; // its from mysql DATETIME and time show when this script will be run
$begintime = "22:00"; // user can choose when this script stop
$endtime = "20:00"; // user can choose when this script run
$mysql_start = explode(' ', $mysql_start);
$taskdays = $mysql_start[0]; // 2018-12-28
echo $taskhours = $mysql_start[1]; // 21:45:00
echo "<br>";
$taskhours = explode(':',$taskhours);
$taskhours = $taskhours[0]; // 22
echo $begintime = date($begintime);
echo "<br>";
$begintime = explode(':',$begintime);
$begintime = $begintime[0]; // 20
echo "<br>";
echo $endtime = date($endtime);
echo "<br>";
$endtime = explode(':',$endtime);
$endtime = $endtime[0] - 1; // because if endtime is 6, so if its 05:59, the endtime will be end on 05
echo $endtime = str_pad($endtime, 2, '0', STR_PAD_LEFT); // if 6, it will add 0 so it will be 06
echo "<br>";
$jamarray = array("00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23");
$ray = array();
if ($begintime > $endtime){
echo '$begintime is bigger than $endtime<br>';
foreach($jamarray as $ray) {
if($ray >= $begintime or $ray <= $endtime){
//echo '<br>';
//print_r($ray);
$eray[] = $ray;
}
}
$aslinya = array_diff($jamarray,$eray);
print_r($aslinya);
if (in_array($taskhours, $aslinya))
{
echo " <= script run in this time";
}
}else{
echo '$begintime is less than $endtime<br>';
foreach($jamarray as $ray) {
if($ray >= $begintime and $ray <= $endtime){
//echo '<br>';
//print_r($ray);
$eray[] = $ray;
}
}
$aslinya = array_diff($jamarray,$eray);
print_r($aslinya);
if (in_array($taskhours, $aslinya))
{
echo " <= script run in this time";
}
}