<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<select>
<?php
include 'connection.php';
$q = "SELECT * FROM rooms WHERE duration='first lecture' and day='Sunday'";
$r = mysql_query($q);
$ro = mysql_num_rows($r);
if($ro==0) {
for($i=1; $i<=14; $i++) { ?>
<option value=""><?php echo $i; ?></option>
<?php
} }
else {
while($row = mysql_fetch_array($r)){
for ($i=1; $i<=14; $i++)
{
$exclude = array($row['name']);
if(in_array($i, $exclude)) continue;
?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php
}
}
}
?>
</select>
</body>
</html>
我想使用 FOR LOOP
来消除一个循环中数组检索的元素。
假设 $row
检索到值 (4,5)
,我想要的 FOR LOOP
是显示 1 到 14 之间的数字,除了 >(4,5)
.
我尝试了很多次并且成功了,但是第一次的循环
仅消除了(4)
,第二次仅消除了(5 )
。
有没有办法同时消除两者?
最佳答案
$row['name']
可能不是数组。变化:
$exclude = array($row['name']);
if(in_array($i, $exclude)) continue;
至
if(+$row['name'] === $i) continue;
关于php - 使用FOR循环消除数组检索到的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37311693/