我想改变钻石的尺寸,但我想使用表格输入。例如,我希望我的钻石尺寸为15,然后是"星星"在中间应该有15,其余的跟随。
这是我目前的代码,在这种情况下,它的大小为" 9",因为钻石中间的星星有9个数。
echo "<table border = 1 align = center>";
// loop for the pyramid
echo "<tr>";
$max = $initAmount = 10; // 10
for($i = 1; $i <= $initAmount; $i += 2) {
$max = $max - 2; // 8
$halfTD = (int) ($max / 2);
echo "<tr>";
for($b = 1; $b <= $halfTD; $b++){
echo "<td></td>";
}
for($j = 1; $j <= $i; $j++) {
echo "<td bgcolor = $color> $char </td>";
}
for($b = 1; $b <= $halfTD; $b++){
echo "<td></td>";
}
echo "</tr>";
}
echo "</tr>";
// loop for the inverted pyramid, so it looks like a diamond
$max = $initAmount = 10;
for($i = 7; $i >= 1; $i -= 2) {
$max = $max - 2;
$diff = $initAmount - $max;
$blankTd = $diff / 2;
echo "<tr>";
for($b = 1 ; $b <= $blankTd; $b++){
echo "<td></td>";
}
for($j = 1; $j <= $i; $j++) {
echo "<td bgcolor = $color> $char </td>";
}
for($b = 1 ; $b <= $blankTd; $b++){
echo "<td></td>";
}
echo "</tr>";
}
echo "</table>";
输出:
我应该在我的代码的哪个部分进行调整以获得自定义大小?