How can I convert a one-dimensional array into a two-dimensional array based on the correlation between key names? Thanks

Source: Internet
Author: User
How can I convert this one-dimensional array into a two-dimensional array based on the correlation between key names? Thank you, big brother! My one-dimensional array is as follows: PHPcode? Array ([xm1] & gt; artificial new pipeline well [dj1] & gt; 300 [sl1] & gt; 100 [zj1] & gt; 30000 [xm2] & gt; bathroom backfilling [dj2] & gt; 100 [sl2] & gt; [how does zj convert this one-dimensional array into a two-dimensional array based on the key-name correlation? Thank you.
Thank you! My one-dimensional array is as follows
PHP code
  ? Array ([xm1] => artificial new pipeline well [dj1] => 300 [sl1] => 100 [zj1] => 30000 [xm2] => toilet backfilling [dj2] => 100 [sl2] => [zj2] => [xm3] => TV background wall [dj3] => 300 [sl3] => [zj3] => [xm4] => living room wine cabinet TV background wine cabinet [dj4] => 100 [sl4] => [zj4] => [xm5] => door-to-door shoe cabinet decoration (activity to send shoe cabinets) [dj5] => 130 [sl5] => [zj5] => [xm6] => bookcase partition (including static cotton interlayer) [dj6] => 200 [sl6] => [zj6] => [xm8] => kitchen mobile door head storage cabinet [dj8] => 200 [sl8] => [zj8] => [xm9] => children's room wardrobe partition (including static cotton interlayer) [dj9] => 100 [sl9] => [zj9] => [xm10] => kitchen cabinets [dj10] => 200 [sl10] => [zj10] => [xm11] => bathroom sink [dj11] => 300 [sl11] => [zj11] => [xm12] => living room, dining room, aisle, gypsum board ceiling [dj12] => 350 [sl12] => [zj12] => [xm13] => bathroom and kitchen integrated ceiling [dj13] => 250 [sl13] => [zj13] => [xm14] => Top and wall dual-fly powder latex paint [dj14] => 200 [sl14] => [zj14] => [xm15] => kitchen, laundry, and bathroom anti-skid floor tiles [dj15] => 120 [sl15] => [zj15] => [xm16] => 300*450 wall tiles [dj16] => 200 [sl16] => [zj16] => [xm17] => window stone laying [dj17] => 200 [sl17] => [zj17] => [xm18] => door Stone [dj18] => 400 [sl18] => [zj18] => [xm19] => Anti-theft window [dj19] => 400 [sl19] => [zj19] => [xm20] => Study door cover [dj20] => 30 [sl20] => [zj20] => [xm21] => bathroom laundry door cover [dj21] => 60 [sl21] => [zj21] => [xm22] => ground and Wall Waterproofing and moisture-proof processing [dj22] => 70 [sl22] => [zj22] => [xm23] => water and circuit transformation [dj23] => 400 [sl23] => [zj23] => [xm24] => finished cleaning service [dj24] => 150 [sl24] => [zj24] => [xm25] => finished product protection fee [dj25] => 200 [sl25] => [zj25] => [xm26] => material shipping [dj26] => 5 [sl26] => [zj26] => [xm27] => junk clear freight [dj27] => 5 [sl27] => [zj27] => [xm28] => kitchen tiles (off discount) [dj28] => 120 [sl28] => [zj28] => [xm29] => kitchen wall tiles (off discount) [dj29] => 140 [sl29] => [zj29] => [xm30] => toilet floor tiles (off discount) [dj30] => 100 [sl30] => [zj30] => [xm31] => toilet wall tiles (off discount) [dj31] => 80 [sl31] => [zj31] => [xm32] => laminate flooring (buy one get one free during activity) [dj32] => 170 [sl32] => [zj32] => [xm33] => bedroom mounting door [dj33] => 730 [sl33] => [zj33] => [xm34] => bathroom door [dj34] => 570 [sl34] => [zj34] => [xm35] => kitchen mobile door [dj35] => 300 [sl35] => [zj35] => [xm36] => wardrobe mobile door [dj36] => 300 [sl36] => [zj36] => [xm37] => kitchen and bathroom ceiling [dj37] => 260 [sl37] => [zj37] => [xm38] => window Stone, cupboard table Stone [dj38] => 260 [sl38] => [zj38] => [xm39] => door Stone [dj39] => 140 [sl39] => [zj39] =>)


I want to convert it to the following
PHP code
  Array ([0] => Array ([xm] => artificial new pipeline well [dj] => 300 [sl] => 100 [zj] => 30000 [1] => Array (......)))


------ Solution --------------------
PHP code
$ Res = array (); foreach ($ arr AS $ k => $ v) {$ res [substr ($ k, 2)-1] [substr ($ k, 0, 2)] = $ v ;} /* Array ([0] => Array ([xm] => artificial new pipeline well [dj] => 300 [sl] => 100 [zj] => 30000) [1] => Array ([xm] => bathroom backfilling [dj] => 100 [sl] => [zj] => )*/

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.