The method and case of implementing matrix transpose operation of two-dimensional array in PHP

Source: Internet
Author: User
This article mainly introduces PHP simple implementation of two-dimensional array of matrix transpose operation, involving PHP for two-dimensional array traversal and operation skills, the need for friends can refer to the next

Specific as follows:

<?php  $arr 1 = Array (array (), array (4,5,6), Array (        6,7,8),        Array (' A ', ' B ', ' C ')      );  Echo ' script home test result:<br><br> ';  Echo ' Matrix transpose before:<br> ';  for ($i =0; $i <count ($arr 1), $i + +) {for    ($j =0; $j <count ($arr 1[$i]), $j + +) {     echo $arr 1[$i] [$j]. ' ';    }    Echo ' <br> ';  }  Echo ' Matrix transpose after:<br> ';  for ($i =0; $i <count ($arr 1); $i + +) {      //Determine number of transpose columns for    ($j =0; $j <count ($arr 1[$i]); $j + +) {  //determine number of transpose lines     $arr 2[$j] [$i] = $arr 1[$i] [$j];   Assign the value of "Row I, Column J" of Matrix 1 to the "line J of Row I"} for Matrix 2    (  $j =0; $j <count ($arr 2); $j + +) {       //iterate over the array 2 for    ($i =0, $i <count ($arr 2[$j]), $i + +) {     echo $arr 2[$j] [$i]. ' ';    }    Echo ' <br> ';  }? >

Run output:

Related recommendations:

PHP merges two sequential array cases

How PHP gets the specified column in the array (case)

PHP six ways to sort arrays

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.