[英]use of break <br> in multidimentional array in php
<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>
因此,上面是多維數組的簡單代碼。 在這里,如果%J == 9,則我使用“ br”標記創建新行,這意味着列數達到9后。 但在多維數組中,它將不起作用。 那么如何創建新行呢?
您可以添加新的div
而不是echo "<br/>";
使用echo "<div style='clear:both'>&nbso or your content if you want to print some thing</div>";
希望這一定能解決您的問題。
您的“ <BR>”被捕獲在<BUTTON>標記內(如果您在chrome下檢查Element,您將看到它,我添加了新行以簡化操作)。 嘗試包括顯式的結束標記:
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 echo ...?>,因為您已經處於PHP模式。
<?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>
標簽
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.