lundi 23 septembre 2019

php if statement with multiple operators (or, and)

I'd like to compare different values before executing a specific function. Including local time, which I get like this:

$localTime = new DateTime('@' . $localTimestamp);
$localTime = [
    0 => $localTime->format('H'),
    1 => $localTime->format('i')
];

// print_r($localTime) looks like this:
Array
(
    [0] => 12
    [1] => 25
)

Here is the if statement:

if ((($localTime[0] === 10) || ($localTime[0] === 11 && $localTime[1] >= 0 && $localTime[1] < 30)) && $localTimestamp - strtotime($latestSession) < 900) { // 15 minutes
    echo 'true';
} else {
    echo 'false';
}

Error: Uncaught Error: Call to undefined function () on line X (line with if statement).

Aucun commentaire:

Enregistrer un commentaire