<html>
<head>
</head>
<body>
<br><br>
<div id="panel1" style="height:500px;width:500px;border-style:solid;color:Blue;">
<div id="top-panel" style="height:40px;width:495px;border-style:solid;color:lavender;"></div>
<div id="mines" style="height:450px;width:495px;border-style:solid;color:lavender;">
<?php
$arr=array(array());
for($i=0;$i<10;$i++)
{
for($j=0;$j<10;$j++)
{
$arr[$i][$j]=0;
if($j==9){
echo "<button type='button' style='height:35px;width:35px;background-color:red;' name='<?php echo $i$j;?>' id='<?php echo $i$j;?>' />";
echo "<br/>";
}
else
{
echo "<button type='button' style='height:35px;width:35px;background-color:Blue;' name='<?php echo $i.$j;?>' id='<?php echo $i$j;?>' />";
}
}
}
for($i=0;$i<10;$i++)
{
for($j=0;$j<10;$j++)
{
$b=rand(1,10);
$c=rand(1,10);
$arr[$b][$c]=1;
}
}
?>
</div>
</div>
</body>
</html>
所以以上是多维数组的简单代码。 在这里,我使用"br"标签来创建新行,如果 %J==9,则表示列号达到 9 之后。 我在表格中做到了,它有效。 但是在多维阵列中,它不起作用。 那么我们如何创建一个新行呢?
你的'
'被困在
if($j==9){
echo "<button type='button' style='height:35px;width:35px;background-color:red;' name='$i$j' id='$i$j' ></button>'n";
echo "<br/>'n";
}
我删除了<?php 回声... ?>,因为您已经处于PHP模式。
您可以添加新的div
而不是echo "<br/>";
使用echo "<div style='clear:both'>&nbso or your content if you want to print some thing</div>";
希望这肯定会解决您的问题。
<?php
$arr=array(array());
for($i=0;$i<10;$i++)
{
for($j=0;$j<10;$j++)
{
$arr[$i][$j]=0;
if($j==9)
{
echo "<button type='button' style='height:35px;width:35px;background-color:red;' name='".$i.$j."' id='".$i.$j."' ></button>";
echo "<br/>";
}
else
{
echo "<button type='button' style='height:35px;width:35px;background-color:Blue;' name='".$i.$j."' id='".$i.$j."' ></button>";
}
}
}
for($i=0;$i<10;$i++)
{
for($j=0;$j<10;$j++)
{
$b=rand(1,10);
$c=rand(1,10);
$arr[$b][$c]=1;
}
}
?>
您没有关闭<button>
标记