Home > Backend Development > PHP Tutorial > 循环嵌套有关问题。好像不难啊小弟我都搞晕了

循环嵌套有关问题。好像不难啊小弟我都搞晕了

WBOY
Release: 2016-06-13 10:20:36
Original
1007 people have browsed it

循环嵌套问题。好像不难啊,我都搞晕了。
有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">
                 
              
              
        
            
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