PHP中的按位与和按位或操作示例
Bitwise AND
按位与主要是对二进制数操作。
代码如下:
复制代码 代码如下:
$a = 1;
$b = 2;
$c = $a^b;
echo $c // 3
?>
这里不是单纯的相加关系
十进制 1换算成二进制 00000001
十进制 2换算成二进制 00000010
按位^ 00000011 // 就是不相同的都算成1 啦 ^_^
然后,
复制代码 代码如下:
$a = 1;
$b = 2;
echo $a & $c; // 1
?>
十进制 3换算成二进制 00000011
十进制 1换算成二进制 00000001
按位& 00000001 // 就是各个位数相同的不变否则都算成0
最后介绍下用法 ; 按位&后返回值是没意义的。 主要是用来判断$a 是否存在于 $c // 权限用法比较多。
复制代码 代码如下:
$my_privilege = 15; // 1+2+4+8 拥有全部权限
$Pri = '';
$privilege_arr = array(8=>'增', 4=>'删',2=>'改',1=>'查');
foreach($privilege_arr as $k =>$v){
$k & $my_privilege && $Pri .= '我有'.$v.'的权力
';
}
echo $Pri;
?>
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
How to fix KB5055523 fails to install in Windows 11?
3 weeks ago
By DDD
How to fix KB5055518 fails to install in Windows 10?
3 weeks ago
By DDD
Roblox: Grow A Garden - Complete Mutation Guide
2 weeks ago
By DDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How to fix KB5055612 fails to install in Windows 10?
3 weeks ago
By DDD

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
Java Tutorial
1663
14


CakePHP Tutorial
1419
52


Laravel Tutorial
1313
25


PHP Tutorial
1264
29


C# Tutorial
1237
24

