mercredi 28 mars 2018

Check against multiple - if not - conditions in PHP

I have two input fields whit start and end time for an event. I only want the time to be in xx:00 or xx:30 format. Front-end is taken care of but I want in validate input in backend. Below is how I retrieve only minutes from posted time.

function validate_time($start_time,$end_time)
{
    $start_time_min = substr($start_time,-2,2);
    $end_time_min = substr($end_time,-2,2);

    if ($start_time_min != '00' || $end_time_min != '00')
    {
        return false;
    }
    if ($start_time_min != '30' || $end_time_min != '30')
    {
        return false;
    }
    return true;
}

Above if statement returns always false, so what I need is to return false only if the start or end time is not 00 or not 30.

Aucun commentaire:

Enregistrer un commentaire