Multiple flags for json_encode ()

How to use multiple flags for php function json_encode ()?

json_encode($array, JSON_PRETTY_PRINT, JSON_UNESCAPED_UNICODE);

This does not work - since only the first flag will be executed, the second will be ignored.

+4
source share
2 answers

You are using a bitmask, as indicated in http://php.net/manual/en/function.json-encode.php :

json_encode($array, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);

This will add binary values JSON_PRETTY_PRINTand JSON_UNESCAPED_UNICODEwith the binary OR operator.

+17
source

These flags are bitmasks . I wrote about this once a long time ago here on SO .

So basically, to use more than one option, you need to or them together

json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
+4

All Articles