Reorganized arrays-PHP recombinant two-dimensional arrays

Source: Internet
Author: User
How to reorganize the original two-dimensional array into the following form?

Original array

Array ([0] = = Array ([1–2 section] = [3–4 section] + Web site development and Maintenance _ weekly _xxxx_01-15 week _s1-205 [第5-6 festival] =&gt ;    Linux Advanced Application _ weekly _xxxx_01-15 week _a-910 [7–8 Festival] + network Security _ every bi-weekly _xxxx_01-15 weeks _a-507 [第9-10 Festival] and [1] = = Array ([1–2 Festival] = IPV6 Technology _ weekly _xxxx_01-14 week _s1-303 [3–4 festival] [第5-6 Festival] and network security _ weekly _xxxx_01-15 week _c-40        8 [7–8] = [第9-10] = [2] = = Array ([1–2 section] + Network Marketing _ weekly _xxxx_01-14 week _c-201 [3–4 Festival] = [第5-6 Festival] = Employment Guidance _ weekly _XXXX_11-12 week _b-202 [7–8 festival] = [第9-10 Festival] = = [3] =&G T         Array ([1–2 section] + Linux advanced application _ every week _xxxx_01-15 weeks _a-910/web website development and Maintenance _ every two weeks _ Zhang Jingpo _01-15 week _a-910 [3–4 Festival] = [第5-6 Festival] + Cisco Advanced Applications _ Weekly _XXXX_01-14 week _s1-305 [7–8 section] + Linux Advanced application _ weekly _xxxx_01-15 week _s1-303 [第9-10 festival] =&gt     ;        ) [4] = = Array ([1–2 section] + network security _ weekly _xxxx_01-15 week _a-508 [3–4 section] + Web site development and Maintenance _ weekly _xxxx_01-15 Week _a-908 [第5-6 Festival] = [7–8] = [第9-10] =)) 

The

Format after reorganization is:

Array ([0] = = Array ([1–2 section] = [1–2 section] + IPV6 technology _ weekly _xxxx_01-14 week _s1-303 [1–2 festival] = Network Marketing _ Weekly _xxxx_01-14 week _c-201 [1–2 festival] + Linux Advanced application _ every week _xxxx_01-15 weeks _a-910/web website development and Maintenance _ every bi-weekly _xxxx_01-15 weeks _a-910 [1–2 Section] + Network security _ weekly _xxxx_01-15 week _a-508) [1] = = Array ([3–4 section] + Web site development and Maintenance _ weekly _xxxx_01-15 Week _s1-205 [ 3–4 [3–4] = [3–4 festival] + [3–4 Festival] + Web site development and Maintenance _ weekly _xxxx_01-15 week _a-908) [2] =&G T Array ([第5-6 section] + Linux Advanced application _ weekly _xxxx_01-15 week _a-910 [第5-6 section] + network security _ weekly _xxxx_01-15 week _c-408 [第5-6 Section] = Employment Guide _ weekly _xxxx_11-12 week _b-202 [第5-6 Festival] + Cisco Advanced Applications _ Weekly _xxxx_01-14 weeks _s1-305 [第5-6 Festival] = [3] =&gt ; Array ([7–8 section] + network security _ _xxxx_01-15 Week _a-507 [7–8 section] [7–8 festival] = [7–8 Festival] =&gt ; Linux Advanced Application _ weekly _xxxx_01-15 week _s1-303 [7–8 festival] + = [4] = = Array ([第9-10 section] = [第9-10 Festival] =&gt         ; [第9-10 Festival] = [第9-10] = [第9-10] =)) 

Reply content:

How to reorganize the original two-dimensional array into the following form?

Original array

Array ([0] = = Array ([1–2 section] = [3–4 section] + Web site development and Maintenance _ weekly _xxxx_01-15 week _s1-205 [第5-6 festival] =&gt ;    Linux Advanced Application _ weekly _xxxx_01-15 week _a-910 [7–8 Festival] + network Security _ every bi-weekly _xxxx_01-15 weeks _a-507 [第9-10 Festival] and [1] = = Array ([1–2 Festival] = IPV6 Technology _ weekly _xxxx_01-14 week _s1-303 [3–4 festival] [第5-6 Festival] and network security _ weekly _xxxx_01-15 week _c-40        8 [7–8] = [第9-10] = [2] = = Array ([1–2 section] + Network Marketing _ weekly _xxxx_01-14 week _c-201 [3–4 Festival] = [第5-6 Festival] = Employment Guidance _ weekly _XXXX_11-12 week _b-202 [7–8 festival] = [第9-10 Festival] = = [3] =&G T         Array ([1–2 section] + Linux advanced application _ every week _xxxx_01-15 weeks _a-910/web website development and Maintenance _ every two weeks _ Zhang Jingpo _01-15 week _a-910 [3–4 Festival] = [第5-6 Festival] + Cisco Advanced Applications _ Weekly _XXXX_01-14 week _s1-305 [7–8 section] + Linux Advanced application _ weekly _xxxx_01-15 week _s1-303 [第9-10 festival] =&gt     ;        ) [4] = = Array ([1–2 section] + network security _ weekly _xxxx_01-15 week _a-508 [3–4 section] + Web site development and Maintenance _ weekly _xxxx_01-15 Week _a-908 [第5-6 Festival] = [7–8] = [第9-10] =)) 

The

Format after reorganization is:

Array ([0] = = Array ([1–2 section] = [1–2 section] + IPV6 technology _ weekly _xxxx_01-14 week _s1-303 [1–2 festival] = Network Marketing _ Weekly _xxxx_01-14 week _c-201 [1–2 festival] + Linux Advanced application _ every week _xxxx_01-15 weeks _a-910/web website development and Maintenance _ every bi-weekly _xxxx_01-15 weeks _a-910 [1–2 Section] + Network security _ weekly _xxxx_01-15 week _a-508) [1] = = Array ([3–4 section] + Web site development and Maintenance _ weekly _xxxx_01-15 Week _s1-205 [ 3–4 [3–4] = [3–4 festival] + [3–4 Festival] + Web site development and Maintenance _ weekly _xxxx_01-15 week _a-908) [2] =&G T Array ([第5-6 section] + Linux Advanced application _ weekly _xxxx_01-15 week _a-910 [第5-6 section] + network security _ weekly _xxxx_01-15 week _c-408 [第5-6 Section] = Employment Guide _ weekly _xxxx_11-12 week _b-202 [第5-6 Festival] + Cisco Advanced Applications _ Weekly _xxxx_01-14 weeks _s1-305 [第5-6 Festival] = [3] =&gt ; Array ([7–8 section] + network security _ _xxxx_01-15 Week _a-507 [7–8 section] [7–8 festival] = [7–8 Festival] =&gt ; Linux Advanced Application _ weekly _xxxx_01-15 week _s1-303 [7–8 festival] + = [4] = = Array ([第9-10 section] = [第9-10 Festival] =&gt         ; [第9-10 Festival] = [第9-10] = [第9-10] =)) 

[1] => Array    (        [第3-4节] => Web网站开发与维护_每周_XXXX_01-15周_S1-205        [第3-4节] =>         [第3-4节] =>         [第3-4节] =>         [第3-4节] => Web网站开发与维护_每周_XXXX_01-15周_A-908    )

This key is the same way of writing, the following key will overwrite the previous, you should be expected to get this result:

[第1-2节] => Array    (        [0] =>         [1] => IPV6技术_每周_XXXX_01-14周_S1-303        [2] => 网络营销_每周_XXXX_01-14周_C-201        [3] => Linux高级应用_每单周_XXXX_01-15周_A-910/Web网站开发与维护_每双周_XXXX_01-15周_A-910        [4] => 网络安全_每周_XXXX_01-15周_A-508    )[第3-4节] => Array    (        [0] => Web网站开发与维护_每周_XXXX_01-15周_S1-205        [1] =>         [2] =>         [3] =>         [4] => Web网站开发与维护_每周_XXXX_01-15周_A-908    )

Can write a function:

    public function listData($arr){        if(empty($arr)) return array();        $listData = array();        foreach($arr as $key=>$value){            foreach($value as $k=>$v){                $listData[$k][] = $v;            }        }        return $listData;    }

Test array

$arr  = array(    0=>array(        'a'=>1,        'b'=>2,        'c'=>3,    ),    1=>array(        'a'=>11,        'b'=>22,        'c'=>33,    ),    2=>array(        'a'=>111,        'b'=>222,        'c'=>333,    ),);

Get:

array  'a' =>     array      0 => int 1      1 => int 11      2 => int 111  'b' =>     array      0 => int 2      1 => int 22      2 => int 222  'c' =>     array      0 => int 3      1 => int 33      2 => int 333
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.