Possible Duplicate:
Reference – What does this symbol mean in PHP?
I am trying to learn PHP and programming.
In the book I am studying there is something like:
$flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE;
$flags is used for the split() method.
The first flag is: If this flag is set, only non-empty pieces will be returned by preg_split().
The second is: If this flag is set, parenthesized expression in the delimiter pattern will be captured and returned as well.
Why isn’t he using && operator but the | ?
Can you please explain what | does actually?
As far as I know these are
&& is the logical AND whereas | is a bitwise operator.
a && bevalutes to true when both operands are evaluted to true. Since flags are almost always numbers greater than 1, this expression always evalutes to true.How functions accepting bitmasks work
They specify constants
Note that these constants have to have powers of 2:
You call the function combining some flags
This leads to a bitwise OR operation:
A set bit (1) in one (or both) of the operands will lead to a set bit (1) in the result, too.
The function checks internally for each flag
This requires a bitwise AND operation:
The bitwise AND required both operands to have a set bit (1) at position X in order to result in a set bit (1) in the result at position X.
Wikipedia has also a nice article about the common bitwise operators: http://en.wikipedia.org/wiki/Bitwise_operation