现有一数组如下
$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' );
需要循环数组实现以下效果
<table> <tbody> <tr> <td>A</td> <td>B</td> <td>C</td> <td>D</td> <td>E</td> <td>F</td> </tr> <tr> <td>a</td> <td>b</td> <td>c</td> <td>d</td> <td>e</td> <td>f</td> </tr> <tr> <td>G</td> <td>H</td> <td>I</td> <td>J</td> <td>K</td> <td>L</td> </tr> <tr> <td>g</td> <td>h</td> <td>i</td> <td>j</td> <td>k</td> <td>l</td> </tr> <tr> <td>M</td> <td>N</td> <td>O</td> <td>P</td> <td>Q</td> <td>R</td> </tr> <tr> <td>m</td> <td>n</td> <td>o</td> <td>p</td> <td>q</td> <td>r</td> </tr> <tr> <td>S</td> <td>T</td> <td>U</td> <td>V</td> <td>W</td> <td>X</td> </tr> <tr> <td>s</td> <td>t</td> <td>u</td> <td>v</td> <td>w</td> <td>x</td> </tr> <tr> <td>Y</td> <td>Z</td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td>y</td> <td>z</td> <td></td> <td></td> <td></td> <td></td> </tr> </tbody> </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' );for($i=0; $i', 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 " ', PHP_EOL;}$v ", PHP_EOL; } echo '
<tr> <td>A</td> <td>B</td> <td>C</td> <td>D</td> <td>E</td> <td>F</td></tr><tr> <td>a</td> <td>b</td> <td>c</td> <td>d</td> <td>e</td> <td>f</td></tr><tr> <td>G</td> <td>H</td> <td>I</td> <td>J</td> <td>K</td> <td>L</td></tr><tr> <td>g</td> <td>h</td> <td>i</td> <td>j</td> <td>k</td> <td>l</td></tr><tr> <td>M</td> <td>N</td> <td>O</td> <td>P</td> <td>Q</td> <td>R</td></tr><tr> <td>m</td> <td>n</td> <td>o</td> <td>p</td> <td>q</td> <td>r</td></tr><tr> <td>S</td> <td>T</td> <td>U</td> <td>V</td> <td>W</td> <td>X</td></tr><tr> <td>s</td> <td>t</td> <td>u</td> <td>v</td> <td>w</td> <td>x</td></tr><tr> <td>Y</td> <td>Z</td> <td></td> <td></td> <td></td> <td></td></tr><tr> <td>y</td> <td>z</td> <td></td> <td></td> <td></td> <td></td></tr>
$item){ $newArray[] = $item; $newArray[] = $values[$key]; } $html = '
$text | ". PHP_EOL; } $tr .= '
<table><tbody><tr><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td><td>F</td></tr><tr><td>a</td><td>b</td><td>c</td><td>d</td><td>e</td><td>f</td></tr><tr><td>G</td><td>H</td><td>I</td><td>J</td><td>K</td><td>L</td></tr><tr><td>g</td><td>h</td><td>i</td><td>j</td><td>k</td><td>l</td></tr><tr><td>M</td><td>N</td><td>O</td><td>P</td><td>Q</td><td>R</td></tr><tr><td>m</td><td>n</td><td>o</td><td>p</td><td>q</td><td>r</td></tr><tr><td>S</td><td>T</td><td>U</td><td>V</td><td>W</td><td>X</td></tr><tr><td>s</td><td>t</td><td>u</td><td>v</td><td>w</td><td>x</td></tr><tr><td>Y</td><td>Z</td><td></td><td></td><td></td><td></td></tr><tr><td>y</td><td>z</td><td></td><td></td><td></td><td></td></tr></tbody></table>
foreach(array_chunk(array_keys($array), 6) as $v){ $len = count($v); if($len < 6){ $v = array_merge($v, array_fill(0, 6-$len, '')); } echo "<tr>\n"; echo "<td>".implode("</td>\n<td>",$v)."</td>\n"; echo "</tr>\n"; $vl = array_map('strtolower', $v); echo "<tr>\n"; echo "<td>".implode("</td>\n<td>",$vl)."</td>\n"; echo "</tr>\n"; }
感谢几位大神的回复 小弟收益匪浅, jordan102 版主可能没理解这个问题的本质其实是想隔行显示标题和内容 ,而不是把大写转为小写的问题 ,可能是我给的数组误导了你,不过如果针对我给数组,你的思路也很值得学习, 再次感谢几位
楼主新人啊!加油!过来凑个热闹!
php 有丰富的数组函数,这里再提供一种写法
$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' );$a = array_map(null, array_chunk(array_keys($array), 6), array_chunk($array, 6));foreach($a as $rs) foreach($rs as $r) { echo "\n"; if(count($r) < 6) $r = array_pad($r, 6, ''); foreach($r as $v) echo " \n"; }$v \n"; echo "
一层循环便可。
$arr = 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' );$page = (int)((count($arr)-1)/6)+1;echo '<table border="1"><tbody>';for($i=0; $i<$page; $i++){ echo '<tr>'; echo '<td>'.implode('</td><td>',array_pad(array_keys(array_slice($arr, $i*6, 6)),6,'')).'</td>'; echo '</tr>'; echo '<tr>'; echo '<td>'.implode('</td><td>',array_pad(array_slice($arr, $i*6, 6),6,'')).'</td>'; echo '</tr>';}echo '</tbody></table>';

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
