I want to to do something when the day is a workday, and do something else when it is a weekend.
But my function echoes “yes” every time, and I don’t get it.
JavaScript
x
var_dump($dag_datumloop);// Saturday is value
if ($dag_datumloop == "Monday" or "Tuesday" or "Wednesday" or "Thursday" or
"Friday"){
echo "yes";
}else if($dag_datumloop == "Saturday" or "Sunday"){
echo "no";
}
Advertisement
Answer
Your current check is only checking to see if $dag_datumloop
is equal to Monday. The rest are being evaluated on their own.
JavaScript
if (($dag_datumloop == "Monday") or ("Tuesday") or ("Wednesday") or ("Thursday") or ("Friday")){
The other days would be evaluated as true
because they’re all string values. The easiest way to check it would to be use in_array
instead of doing $dag_datumloop ==
for each one:
JavaScript
if(in_array($dag_datumloop, ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']))