循环嵌套问题。好像不难啊,我都搞晕了。
有4个类目:
类目1:(一,二)
类目2:(A,B,C,D)
类目3:(a,b,c,d)
类目4:(甲,乙,丙,丁)
想要达到下面的效果,怎么循环?表要怎么建?一句SQL语句好像肯定搞不定吧?
一Aa,一Ab,一Ac,一Ad,
一A甲,一A乙,一A丙,一A丁,
一Ba,一Bb,一Bc,一Bd,
一B甲,一B乙,一B丙,一B丁,
一Ca,一Cb,一Cc,一Cd,
一C甲,一C乙,一C丙,一C丁,
一Da,一Db,一Dc,一Dd,
一D甲,一D乙,一D丙,一D丁,
一a甲,一a乙,一a丙,一a丁,
一b甲,一b乙,一b丙,一b丁,
一c甲,一c乙,一c丙,一c丁,
一d甲,一d乙,一d丙,一d丁,
二Aa,二Ab,二Ac,二Ad,
二A甲,二A乙,二A丙,二A丁,
二Ba,二Bb,二Bc,二Bd,
二B甲,二B乙,二B丙,二B丁,
二Ca,二Cb,二Cc,二Cd,
二C甲,二C乙,二C丙,二C丁,
二Da,二Db,二Dc,二Dd,
二D甲,二D乙,二D丙,二D丁,
二a甲,二a乙,二a丙,二a丁,
二b甲,二b乙,二b丙,二b丁,
二c甲,二c乙,二c丙,二c丁,
二d甲,二d乙,二d丙,二d丁,
------解决方案--------------------
- PHP code
<?php $arr_1=array('一','二'); $arr_2=array('A','B','C','D'); $arr_3=array('a','b','c','d'); $arr_4=array('甲','乙','丙','丁'); $temp=array(); foreach($arr_2 as $v) foreach(array_merge($arr_3,$arr_4) as $sv){ $temp[]=$v.$sv; } foreach($arr_3 as $v){ foreach($arr_4 as $sv) $temp[]=$v.$sv; } foreach($arr_1 as $v){ foreach($temp as $sv) $arr[]=$v.$sv; } print_r(array_chunk($arr,4)); <div class="clear">

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
