Home > Backend Development > PHP Tutorial > User rights management code_PHP tutorial

User rights management code_PHP tutorial

WBOY
Release: 2016-07-13 10:58:27
Original
1236 people have browsed it

用户权限管理代码

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 < Count($ruleArr); $i++)
                {
                        if($ruleArr[$i] <= 0 ) continue;
                        $turnData = pow(2, $ruleArr[$i]) - 1 << $usedBit & $data;
                        $varData[$i] = $turnData >> $usedBit;

                        $usedBit += $ruleArr[$i];
                }
        }
        else
        {
                for($i = 0, $cnt = Count($ruleArr); $i < $cnt; $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 < Count($ruleArr); $i++)
                {
                        if($ruleArr[$i] <= 0 ) continue;

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

            $rslt |= $data[$i] << $usedBit;

                        $usedBit += $ruleArr[$i];
                }
        }
        else
        {
                for($i = 0, $cnt = Count($ruleArr); $i < $cnt; $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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template