我有这个代码
foreach ($objWorksheet->getRowIterator() as $row) {
$output[] = array();
//adding a blank array to the end doesn't seem to
//advance the array pointer so do it manually.
$test = end($output);
$cellIterator = $row->getCellIterator();
foreach ($cellIterator as $cell) {
//specifically this bit
$output[key($output)][] = $cell->getValue();
}
}
Run Code Online (Sandbox Code Playgroud)
但我不喜欢我如何使用当前密钥
$output[key($output)][] = $cell->getValue();
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?
你为什么不使用另一个变量?
foreach ($objWorksheet->getRowIterator() as $row) {
$cells = array();
foreach ($row->getCellIterator() as $cell) {
$cells[] = $cell->getValue();
}
$output[] = $cells;
}
Run Code Online (Sandbox Code Playgroud)