Confused about PHP || and && Operator functionality

Hello,
after playing around with a while loop I am actually confused on how the Boolean operators ‘||’ and ‘&&’ work in PHP. I have a background in C++ and I expected the operators logic to be similar, but after some playing around I realized that if I used the “||” operator, it results in an infinite loop (referring to the first block of code below). I’m not sure how to wrap up my point, but I was expecting “||” to parse all boolean expressions and return TRUE if ONE of the expressions are true and “&&” to check all boolean expressions and only return TRUE if ALL expressions were true. Is the behavior different in PHP? I would really appreciate if someone could clear this up for me, and sorry if the way I phrased my question is confusing.

//Display a menu for the user to choose from
  echo "MAGIC 8-BALL MENU\n-----------------\nA) Gain wisdom\nQ) Quit Program\nPlease make a selection: \n";
  $selection = readline(">> ");
//Attempt to valid input, but results in infinite loop no matter the input.
  while($selection != "a" || $selection != "A" || $selection != "q" || $selection != "Q"){
    echo "\nYou've made an invalid selection. Please try again: \n";
    $selection = readline(">> ");
  }

Thank you in advance to anyone who might help, and if you want any clarification just let me know :slight_smile:

That would be an infinite loop in any language. If any of the conditions evaluate to true, the loop will execute. All but one of those at the least will always evaluate to true.