php随机数, php运算符(杂)

WBOY
Release: 2016-06-23 14:29:37
Original
968 people have browsed it

// 生成php随机数
function  randomkeys( $length )
{
     $pattern   =   ' 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ,./<>?;#:@~[]{}-_=+)(*&^%___FCKpd___0pound;"! ' ;  // 字符池
     for ( $i = 0 ; $i     {
         $key   .=   $pattern { mt_rand ( 0 , 35 )};  // 生成php随机数
    }
     return   $key ;
}


// ------------------------------------
$num   =   3 ;
// 取低16位,高位部分全部都为0
$num   &   0x00FF ;  // 3

//左移  $num  
//右移 >>, 高位补0
$num   >>   1 ;  // 1


//------------------------------------
//位运算符 & 按位与运算
//都是1的才设为1, 7:bin(111), 2:bin(10), 7&2 输出bin(10),十进制为2
//权限操作
define ( ' READ ' ,   1 );
define ( ' WRITE ' ,   2 );
define ( ' DELETE ' ,   4 );

// User Permisssion 1:read 2:write 3:read+write 4:delete 5:read+delete 6:write+delete 7:all
$userPermisssion   =   4 ;
// 判断用户是否有权限, 为0则没有权限.
if  ( ! $userPermisssion   &  READ)
{
     // access die
}

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!