convert array 90 degree - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of convert array 90 degree.php

  1. <?php
  2.  
  3. $array = [
  4.     0=>[1,2,3],
  5.     1=>[4,5,6],
  6.     2=>[7,8,9],
  7. ];
  8.  
  9.  
  10. $res = [];
  11. $array = array_reverse($array);
  12.  
  13. $countArray = count($array)-1;
  14. for ($i = 0; $i <= $countArray ; $i++){
  15.     $temp = [];
  16.     foreach($array as $key=>$arr){
  17.         $temp[] = $arr[$i];
  18.     }
  19.     $res[] =$temp;
  20. }
  21.  
  22. print_r($res);
File Description
  • convert array 90 degree
  • PHP Code
  • 30 Jan-2020
  • 328 Bytes
You can Share it: