Page 1 of 1

Rows into Columns and Columns into Rows?

Posted: Fri Oct 14, 2005 11:23 am
by Siryx
I got a text file, i read it then i need to change the rows into columns and columns into rows.

the text file i got is like this:

Oct-12|2585|5828|589|382|4821
Oct-13|2450|1828|525|342|1821
Oct-14|3455|1528|545|482|1421
Oct-15|2455|1588|345|982|1482
Oct-16|2555|1582|576|122|1911
Oct-17|2585|1310|685|981|1761

how can i switch and save the result in other text file?

thanks

Posted: Fri Oct 14, 2005 1:11 pm
by feyd
rotate clockwise:

Code: Select all

for($x = 0; $x < count($data[0]); $x++) {
  for($y = 0; $y < count($data); $y++) {
    $new[$x][$y] = $data[$y][$x];
  }
}

Posted: Fri Oct 14, 2005 2:07 pm
by Siryx
now i got a big problem.

i can read all the row, but i can read data by data.

i read: $data1=Oct-12|2585|5828|589|382|4821

but i want to read:

$data1[1]=Oct-12
$data1[2]=2585
$data1[3]=5828
$data1[4]=589
$data1[5]=382
$data1[6]=4821

$data2[1]=Oct-13
... etc

how can i separate each data? with the data in order, i will just rotate clockwise.
any help, thanks

Posted: Fri Oct 14, 2005 2:35 pm
by foobar

Code: Select all

$data1 = explode('|', $data1);