2013-07-25 1 views
1
<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에 도달 한 후에 의미합니다. 테이블에서 작업을 수행했습니다. 하지만 다차원 배열에서는 작동하지 않습니다. 그래서 우리는 어떻게 새로운 라인을 만들 수 있습니까?PHP의 다차원 배열에서 <br>의 사용

답변

0

귀하의 '<BR>'는 < 버튼 > 태그 안에 잡힌 (당신은 크롬에서 요소를 검사하는 경우 당신이 그것을 볼거야, 나는 그것을 쉽게하기 위해 새로운 라인을 추가)지고 있습니다. 명시적인 종료 태그를 포함 해보십시오 : ? php echo ...을 (를) 삭제 했습니까?

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 모드에 있기 때문에 u는 버튼 태그는 문제가 언급 한 바와 같이

+0

예를 닫지 않았다. 나는 버튼을위한 끝 태그를 작성하지 않았다. 끝 태그를 올린 후. thnkx .. 그리고 newline-n이 필요 없습니다. br는 종료 버튼 태그 후 작업 중입니다. 또한 나는 서두 르기 때문에 user1638279

0

당신은 사용이 확신으로 문제를 해결할 수 "<div style='clear:both'>&nbso or your content if you want to print some thing</div>";

희망을 에코 새로운 div 대신 echo "<br/>";의를 추가 할 수 있습니다.

0
<?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> 태그

관련 문제