They are just constants which map to a number, e.g. SORT_NUMERIC
(a constant used by sorting functions) is the integer 1
.
Check out the examples for json_encode()
.
As you can see, each flag is 2n. This way, |
can be used to specify multiple flags.
For example, suppose you want to use the flag JSON_FORCE_OBJECT
(16
or 00010000
) and JSON_PRETTY_PRINT
(128
or 10000000
).
The bitwise operator OR (|
) will turn the bit on if either operand's bit is on...
JSON_FORCE_OBJECT | JSON_PRETTY_PRINT
...is internally....
00010000 | 1000000
...which is...
10010000
You can check it with...
var_dump(base_convert(JSON_PRETTY_PRINT | JSON_FORCE_OBJECT, 10, 2));
// string(8) "10010000"
CodePad.
This is how both flags can be set with bitwise operators.
var_dump()
the cosntant, it'll show you the content. – Bernice