0
我創建了一個座位預訂網站,這裏是簡化位置的代碼。我有一個名爲「預訂」的數組,其中包含已預訂的座位。 每當座位號碼等於「預訂」數組中的任何數字時,如何將div標識ID更改爲「預訂」?座位預訂
<?php
$rows = 20;
$cols = 10;
$currentnr;
$booked = array(1, 4, 100, 199);
echo "<table border='1'>";
for($tr=1;$tr<=$rows;$tr++){ // Going through every row
echo "<tr>";
for($td=1;$td<=$cols;$td += 2){ // Going through every column (2 at a time)
$currentnr = ($tr * 10 - 10 + $td); // Calculates the current nr
// ---------This id \/
echo "<td><div id='free'><p>".$currentnr."</p></div></td>";
echo "<td><div id='free'><p>".($currentnr + 1)."</p></div></td>";
}
echo "</tr>";
}
echo "</table>";
?>
看看'in_array'函數 - http://uk1.php.net/in_array –