0

ok here is some code

$highestRow = 16; // e.g. 10
$highestColumn = 'F'; // e.g 'F'

$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5


for ($row = 9; $row <= $highestRow; ++$row) {
$val=array(); //i have initialized the array
  for ($col = 1; $col <= $highestColumnIndex; ++$col) {
   $cell=$objWorksheet->getCellByColumnAndRow($col, $row);
   $val[]=$cell->getValue();

  }
echo $val[0] //from what is read from excel, it returns data like this 7563
}

How the data was in the excel sheet before, B9 had 75, B10 had 6 and B11 had 3

After reading i echo $val[0] //output 7563

Now i would like to add additional data to the result so if i echo $val[0] after adding the info it shows the output as

echo $val[0] //output average=75% ; rsd = 6%; n=3% instead of just 7563
Cobra_Fast
  • 15,671
  • 8
  • 57
  • 102
alphy
  • 931
  • 4
  • 13
  • 23
  • Does "xyz" accurately represent the real data? Is it literally "xyz", Is it a string? a number? how is it formatted? – Herbert Jun 30 '13 at 14:34
  • I don't fully understand your question but I'll give it a try. You have an array called $k. In that array you have a key[0], which contains "average = x; rsd = y; n=z" Do you want to add a new key or change a certain key in that array ? – user1928075 Jun 30 '13 at 14:09
  • I have edited the question with some code, hope its clear now – alphy Jun 30 '13 at 14:54
  • Thanks for updating. That certainly sheds more light on the matter. I still don't understand why `getCellByColumnAndRow` reads 3 columns at a time. Granted I'm not familiar with PHPExcel, but the inner `for` loop reads each column in turn, so I would expect `$val[0]=75`, `$val[1]=6`, and `$val[2]=3` -- incrementing for each `$val[]=$cell->getValue();` What am I missing? – Herbert Jun 30 '13 at 15:58
  • Perhaps you could try `echo $cell->getValue();` inside the inner `for` loop. I suspect there's a better way to organize your data with associative arrays, but I'm not understanding why the data is clumped together like that. – Herbert Jun 30 '13 at 16:01

2 Answers2

0
foreach ($k as $key=>$value) {
    echo $key."=".$value."; ";
}
vladkras
  • 16,483
  • 4
  • 45
  • 55
0

Depending on the type of array that you have you can either directly edit it as a string, or you have to turn it into a string.

If the value is already a string you can simply do string manipulation, you can create a temporary or use the original string and edit it all at once to be echoed, depends on what you prefer.

$strTemp = "output average=substr($var[0],0,2)% ; "rsd =substr($var[0]%,2,1); n=substr($var[0]%,3,1);" //can also use $var[0] instead of strTemp

If the values are in integer format you will have to turn the values into strings and then you can move on from there. If you don't know how, I advise this thread: Converting an integer to a string in PHP

Another thing, I'd advise storing the numbers in different parts of the array, that way its easier to reference them and tell them apart.

Community
  • 1
  • 1
Mason
  • 139
  • 1
  • 12