What does this statement mean?

While

$w is an Array ( [0] => 4, [1] => 6 )

what does this expression mean:

$day == $w[0] || $day == $w[1] || $day < ((7 + $w[1] - $w[0]) % 7);

Please, help. I have not seen the statement ||inside, except for the if or while statement. Thanks.

EDIT 01:

This is the original function in which it is used to search for a specific day in a date range:

// find number of a particular day (sunday or monday or etc) within a date range
function number_of_days($day, $start, $end){
    $w = array(date('w', $start), date('w', $end));
    return floor( ( date('z', $end) - date('z', $start) ) / 7) + ($day == $w[0] || $day == $w[1] || $day < ((7 + $w[1] - $w[0]) % 7));
}

It was not created by me. But I wanted to edit this function, because when the end of the day is Saturday, it also takes into account next Sunday, which is wrong.

+3
source share
4 answers

It is simply a complex boolean expression that returns trueif any of the following four subexpressions true::

  • $day == $w[0]
  • $day == $w[1]
  • $day < ((7 + $w[1] - $w[0]) % 7)
+7
source
$day == $w[0] || $day == $w[1] || $day < ((7 + $w[1] - $w[0]) % 7);

( ) true/false.

true || false || false => true

false || false || false => false

, "" , true. $v = expression if (expression)

+4
source

|| is a logical OR operator. See more details.

+2
source

Source: https://habr.com/ru/post/1727759/


All Articles