Is code 1 equal to code 2?
Yes. Code 1 uses nested ternary operator
while code 2 uses the else-if
structure. Code 1 would've been more clear if parentheses were used to show the precedence.
What do &
and ~
mean?
&
in php refers to BITWISE AND operator. ~
in php refers to BITWISE NOT or Complement operator. In this case, it gives the complement values of the constants.
However, you need to know that ~
has the highest precedence here.