These are just constants that map to a number, for example. SORT_NUMERIC (the constant used by the sort functions) is an integer of 1 .
Check out the examples for json_encode() .
As you can see, each flag is 2 n . Thus, | can be used to indicate multiple flags.
For example, suppose you want to use the JSON_FORCE_OBJECT ( 16 or 00010000 ) and JSON_PRETTY_PRINT ( 128 or 10000000 ) JSON_PRETTY_PRINT .
The bitwise OR ( | ) operator will turn on the bit if the bit of the operand bit is turned on ...
JSON_FORCE_OBJECT | JSON_PRETTY_PRINT
... internally ....
00010000 | 1000000
... which the...
10010000
You can check this with ...
var_dump(base_convert(JSON_PRETTY_PRINT | JSON_FORCE_OBJECT, 10, 2)); // string(8) "10010000"
CodePad
Thus, both flags can be set using bitwise operators.
source share