比特和位掩码是我一直在努力理解的东西,但我想学习如何将它们用于PHP中的设置和类似的东西.
我终于找到了一个声称要做到这一点的课程,而且正如我所知,它似乎有效,但我不确定这是否是最好的方法.我将使用下面的示例代码发布类文件,以便按工作顺序显示它.
如果您有经验,请告诉我是否可以改进,性能或其他任何方面.我真的很想学习这个,而且我一直在阅读它,但到目前为止我很难掌握它.
班级...
<?php
class bitmask
{
/**
* This array is used to represent the users permission in usable format.
*
* You can change remove or add valuesto suit your needs.
* Just ensure that each element defaults to false. Once you have started storing
* users permsisions a change to the order of this array will cause the
* permissions to be incorectly interpreted.
*
* @type Associtive array
*/
public $permissions = array(
"read" => …Run Code Online (Sandbox Code Playgroud)