<?php
if(!empty($_POST))
{
$m=0;
for($i=0;$i<sizeof($_POST['p']);++$i)
{
$m |= $_POST['p'][$i];
}
}
?>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> 与运算符和或运算符(&和|) </title>
<meta name="Author" content="Libch">
<meta name="Keywords" content="">
<meta name="Description" content="">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link href="" rel="stylesheet" type="text/css" />
<script language="javascript">
</script>
</head>
<body>
<form name="form" method="POST" action="andmark.php">
<input type="checkbox" name="p[]" value="2" <?php if($m & 2) echo "checked";?>>选择1<br>
<input type="checkbox" name="p[]" value="4" <?php if($m & 4) echo "checked";?>>选择2<br>
<input type="checkbox" name="p[]" value="8" <?php if($m & 8) echo "checked";?>>选择3<br>
<input type="submit" value="Click">
</form>
</body>
</html>
if(!empty($_POST))
{
$m=0;
for($i=0;$i<sizeof($_POST['p']);++$i)
{
$m |= $_POST['p'][$i];
}
}
?>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> 与运算符和或运算符(&和|) </title>
<meta name="Author" content="Libch">
<meta name="Keywords" content="">
<meta name="Description" content="">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link href="" rel="stylesheet" type="text/css" />
<script language="javascript">
</script>
</head>
<body>
<form name="form" method="POST" action="andmark.php">
<input type="checkbox" name="p[]" value="2" <?php if($m & 2) echo "checked";?>>选择1<br>
<input type="checkbox" name="p[]" value="4" <?php if($m & 4) echo "checked";?>>选择2<br>
<input type="checkbox" name="p[]" value="8" <?php if($m & 8) echo "checked";?>>选择3<br>
<input type="submit" value="Click">
</form>
</body>
</html>