CodeX
Published in

CodeX

How to use bitmasks in PHP

Or other languages. It’s the same concept.

Bitmasks are as old as computing itself and, admittedly, were more useful in the days of memory scarcity and low-level programming. But there’s nothing to stop you using them today, when appropriate.

PHP makes use of bitmasks in many of its built-in functions. Consider:

json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

(my personal favourite way of calling json_encode…)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store