I have my data in excel similar to
If we select, copy those cells. Then transpose it, we get the below result (Select any other cell, right click, paste special, transpose) This is how we transpose in excel
I need a PHP script, which will read my excel like first image, transpose and give me a csv file like image 2. The excel can do the transpose, but can any script do?
It's not exactly difficult in PHP starting from an array
$startArray = array(
array('Animal','','',''),
array('Mamals','','Birds',''),
array('Whales','Humans','Eagle','Hen'),
);
$result = array();
foreach ($startArray as $key => $value) {
foreach($value as $key2 => $value2) {
$result[$key2][$key] = $value2;
}
}
var_dump($result);
If you're starting from an Excel file, then you need a library like PHPExcel to read the cells to an array, update the worksheet after the transpose, and write the file again