Php converts a one-dimensional array to a two-dimensional array consisting of three consecutive values. php traverses a two-dimensional array. php defines a two-dimensional array.

Source: Internet
Author: User
A two-dimensional array. php: php converts a one-dimensional array to a two-dimensional array consisting of three consecutive values: this example describes how php converts a one-dimensional array to a two-dimensional array consisting of three consecutive values. For your reference, the running result is as follows: Array (this example describes how php converts a one-dimensional Array to a two-dimensional Array consisting of three consecutive values. We will share this with you for your reference. The details are as follows:

<? Php $ aaa = array ('A', 'BB ', 'CC', 'DD', 'ee', 'FF ', 'GG', 'hh ', 'II'); for ($ I = 0; $ I <3; $ I ++) {$ bbb [] = array_slice ($ aaa, $ I * 3, 3) ;}print_r ($ bbb) ;?>

The running result is as follows:

Array ([0] => Array ([0] => aa [1] => bb [2] => cc) [1] => Array ([0] => dd [1] => ee [2] => ff) [2] => Array ([0] => gg [1] => hh [2] => ii ))

Key code:

$ Bbb [] = array_slice ($ aaa, $ I * 3, 3); // 3 is a group of three. if it is a group of two, 2 is a group of two.

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.