PHP 2D array rectangle transpose instance, 2D array rectangle

Source: Internet
Author: User

PHP 2D array rectangle transpose instance, 2D array rectangle

PHP two-dimensional array rectangular transpose instance

<? Php // transpose a two-dimensional array // defines a two-dimensional array $ arr = array (, 3), array (, 6 )); // define an array to hold transposed data $ arr1 = array (); // traverse echo before transpose: <br/> "; for ($ I = 0; $ I <count ($ arr); $ I ++) {for ($ j = 0; $ j <count ($ arr [$ I]); $ j ++) {echo $ arr [$ I] [$ j];} echo "<br/>";} echo "before and after transpose: <br/> "; // determine the number of rows after the device ($ j = 0; $ j <count ($ arr [0]); $ j ++) {$ arr1 [$ j] = array () ;}for ($ I = 0; $ I <count ($ arr); $ I ++) {for ($ j = 0; $ j <count ($ arr [$ I]); $ j ++) {$ arr1 [$ j] [$ I] = $ arr [$ I] [$ J]; // echo $ arr ;}// transpose traversal: for ($ k = 0; $ k <count ($ arr1); $ k ++) {for ($ l = 0; $ l <count ($ arr1 [$ k]); $ l ++) {echo $ arr1 [$ k] [$ l];} echo "<br/>" ;}?>

The above two-dimensional PHP array rectangular transpose example is all the content shared by the editor. I hope to give you a reference, and hope you can also support the help house.

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.