首页 >后端开发 >php教程 >用户权限管理代码_PHP教程

用户权限管理代码_PHP教程

WBOY
WBOY原创
2016-07-13 10:58:271222浏览

用户权限管理代码

define('PATTERN_MODE_INT',                1);
define('PATTERN_MODE_STRING',        2);

function bitToArray($data, $ruleArr, $mode = PATTERN_MODE_INT)
{
        $varData = array();

        if($mode == PATTERN_MODE_INT)
        {
                $usedBit = 0;
               
                for($i = 0; $i                 {
                        if($ruleArr[$i]                         $turnData = pow(2, $ruleArr[$i]) - 1                         $varData[$i] = $turnData >> $usedBit;

                        $usedBit += $ruleArr[$i];
                }
        }
        else
        {
                for($i = 0, $cnt = Count($ruleArr); $i                 {
                        $varData[$i] = substr($data, $i, $ruleArr[$i]);
                }
        }

        return $varData;
}

function arrayToBit($data, $ruleArr, $mode = PATTERN_MODE_INT)
{
        $rslt = '';

        if($mode == PATTERN_MODE_INT)
        {
                $usedBit        = 0;
                $rslt                = 0;
               
                for($i = 0; $i                 {
                        if($ruleArr[$i]

                        if(!$data[$i]) $data[$i] = 0;

            $rslt |= $data[$i]

                        $usedBit += $ruleArr[$i];
                }
        }
        else
        {
                for($i = 0, $cnt = Count($ruleArr); $i                 {
                        $rslt .= sprintf('%0' . $ruleArr[$i] . 's', $data[$i]);
                }
        }
       
        return $rslt;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632012.htmlTechArticle用户权限管理代码 define('PATTERN_MODE_INT', 1); define('PATTERN_MODE_STRING', 2); function bitToArray($data, $ruleArr, $mode = PATTERN_MODE_INT) { $varData = array(); if($m...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn