The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS PHP question.

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #37459
    Ricardo C.

    What does this mean “||” in php?


    Correct, “||” means “OR” when used in a conditional statement.

    Fun Fact: in karlpcrowly’s example (and in all instances where “||” is used), if a condition ends up as TRUE, it will ignore and not solve all following conditions and simply move onto the code contained in the brackets.

    For example:

    $var = 2;
    if($var > 1 || $var > 0){
    echo "success";

    Above, the first condition is TRUE so it will ignore the "$var > 0" condition and just continue on.

    So if you need to use "||" try to put the one mostly likely to be solved TRUE for first that way it only has to calculate 1 statement most of the time.

    Also, on an irrelevant note, in karlpcrowly's "if" statement, the first condition is not needed as all numbers greater than 1 are greater than 0 as well, so anything that would be TRUE for the fist statement is also TRUE for the 2nd. Just wanted to clear that up for ricky122892 so he isn't potentially confused.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘CSS’ is closed to new topics and replies.