Rows into Columns and Columns into Rows?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Siryx
Forum Newbie
Posts: 11
Joined: Tue Jul 26, 2005 9:58 am

Rows into Columns and Columns into Rows?

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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];
  }
}
Siryx
Forum Newbie
Posts: 11
Joined: Tue Jul 26, 2005 9:58 am

Post 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
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Code: Select all

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