Maison > Article > développement back-end > 一个关于数组循环的有关问题
一个关于数组循环的问题
现有一数组如下
$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 />
<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>
$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; $iecho ' ', PHP_EOL; ', 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 '
echo '', PHP_EOL; ', PHP_EOL;
foreach($t2 as $v) {
echo "$v ", PHP_EOL;
}
echo '
}
<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>