I am trying to compare 2 times in PHP. I fetched and stored the time in notepad from Mysql, like 21:30
22:00
22:30
then I reading time from the file and storing it in an array.
$myfile = file('Scheduled_data.txt');
$time_array = array();
// store into array
foreach ($myfile as $line) {
$line_array = explode("\t", $line);
$time_array[] = $line_array[0];
}
//looping array
for ($i = 0; $i < count($time_array); $i++) {
$timezone = new DateTime("now", new DateTimeZone('Asia/Kolkata') );
$current_time=$timezone->format('H:i');
echo $time_array[$i]; //ex: first data 21:30
echo "\t";
echo $current_time; // 21:30
if($time_array == $current_time)
{
echo "yes"; // not moving inside if cond
}
}
not moving inside if condition. but I can see the same time while printing (echo).
Updated: Sorry i did this only but still not going inside if
if($time_array[$i] == $current_time)
{
echo "yes"; // not moving inside if cond
}
Note both type is string only and tried of compare using === still no use.
Aucun commentaire:
Enregistrer un commentaire