一个关于数组循环的有关问题

WBOY
Release: 2016-06-13 12:02:32
Original
912 people have browsed it

一个关于数组循环的问题
现有一数组如下

$array = array ('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e', 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j', 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o', 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't', 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y', 'Z' => 'z' );<br />
Copy after login


需要循环数组实现以下效果
<table><br />		<tbody><br />			<tr><br />				<td>A</td><br />				<td>B</td><br />				<td>C</td><br />				<td>D</td><br />				<td>E</td><br />				<td>F</td><br />			</tr><br />			<tr><br />				<td>a</td><br />				<td>b</td><br />				<td>c</td><br />				<td>d</td><br />				<td>e</td><br />				<td>f</td><br />			</tr><br />			<tr><br />				<td>G</td><br />				<td>H</td><br />				<td>I</td><br />				<td>J</td><br />				<td>K</td><br />				<td>L</td><br />			</tr><br />			<br />			<tr><br />				<td>g</td><br />				<td>h</td><br />				<td>i</td><br />				<td>j</td><br />				<td>k</td><br />				<td>l</td><br />			</tr><br />			<tr><br />				<td>M</td><br />				<td>N</td><br />				<td>O</td><br />				<td>P</td><br />				<td>Q</td><br />				<td>R</td><br />			</tr><br />			<tr><br />				<td>m</td><br />				<td>n</td><br />				<td>o</td><br />				<td>p</td><br />				<td>q</td><br />				<td>r</td><br />			</tr>			<br />			<tr><br />				<td>S</td><br />				<td>T</td><br />				<td>U</td><br />				<td>V</td><br />				<td>W</td><br />				<td>X</td><br />			</tr><br />			<tr><br />				<td>s</td><br />				<td>t</td><br />				<td>u</td><br />				<td>v</td><br />				<td>w</td><br />				<td>x</td><br />			</tr><br />			<tr><br />				<td>Y</td><br />				<td>Z</td><br />				<td></td><br />				<td></td><br />				<td></td><br />				<td></td><br />			</tr>	<br />			<tr><br />				<td>y</td><br />				<td>z</td><br />				<td></td><br />				<td></td><br />				<td></td><br />				<td></td><br />			</tr><br />		</tbody><br />	</table>
Copy after login


请问各位该如何实现呢
------解决方案--------------------
$array = array ('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e', 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j', 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o', 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't', 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y', 'Z' => 'z' );<br />
for($i=0; $i echo '', PHP_EOL;
$t1 = array_keys(array_slice($array, $i, 6)) + array_fill(0, 6, '');
$t2 = array_values(array_slice($array, $i, 6)) + array_fill(0, 6, '');
foreach($t1 as $v) {
echo " $v", PHP_EOL;
}
echo '', PHP_EOL;

echo '', PHP_EOL;
foreach($t2 as $v) {
echo " $v", PHP_EOL;
}
echo '', PHP_EOL;
}
Copy after login

<tr>
<br>  <td>A</td>
<br>  <td>B</td>
<br>  <td>C</td>
<br>  <td>D</td>
<br>  <td>E</td>
<br>  <td>F</td>
<br>
</tr><br><tr>
<br>  <td>a</td>
<br>  <td>b</td>
<br>  <td>c</td>
<br>  <td>d</td>
<br>  <td>e</td>
<br>  <td>f</td>
<br>
</tr><br><tr>
<br>  <td>G</td>
<br>  <td>H</td>
<br>  <td>I</td>
<br>  <td>J</td>
<br>  <td>K</td>
<br>  <td>L</td>
<br>
</tr><br><tr>
<br>  <td>g</td>
<div class="clear">
                 
              
              
        
            </div>
</tr>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template