How to use bitmasks in PHP

Or other languages. It’s the same concept.

Bobby Jack
CodeX
Published in
4 min readMar 28, 2022

--

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…)

--

--

Bobby Jack
CodeX
Writer for

Technologist & writer, Bobby is an Editor at consumer tech site makeuseof.com and ex-Editor-in-Chief of Switch Player Magazine. Read lots more at bobbyjack.me.