Home > Article > Backend Development > php随机数, php运算符(杂)
// 生成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
}