PHP这样写对不对?如果有更好的写法告诉我怎么写
<?php$D1=1;$D2=2;$D3=4;$D4=8;$D5=16;$state=13;$r1=$state&D1;if($r1>0){echo"<br/>灯1亮";...
<?php
$D1 = 1;
$D2 = 2;
$D3 = 4;
$D4 = 8;
$D5 = 16;
$state = 13;
$r1 = $state & D1;
if($r1 > 0){
echo "<br/>灯1亮";
}else{
echo "<br/>灯1灭";
}
$r1 = $state & D2;
if($r1 > 0){
echo "<br/>灯2亮";
}else{
echo "<br/>灯2灭";
}
for($i = 1;$i <= 5;++$i){
$temp = "D".$i;
$r1 = $state & $$temp;
if($r1 > 0){
echo "<br/>灯{$i}亮";
}else{
echo "<br/>灯{$i}灭";
}
}
?> 展开
$D1 = 1;
$D2 = 2;
$D3 = 4;
$D4 = 8;
$D5 = 16;
$state = 13;
$r1 = $state & D1;
if($r1 > 0){
echo "<br/>灯1亮";
}else{
echo "<br/>灯1灭";
}
$r1 = $state & D2;
if($r1 > 0){
echo "<br/>灯2亮";
}else{
echo "<br/>灯2灭";
}
for($i = 1;$i <= 5;++$i){
$temp = "D".$i;
$r1 = $state & $$temp;
if($r1 > 0){
echo "<br/>灯{$i}亮";
}else{
echo "<br/>灯{$i}灭";
}
}
?> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询