Answer the question
In order to leave comments, you need to log in
How to provide a cycle not with a series of numbers, but only some?
$notInResult = [0,1,2,4,5,7,8];
for ($j = 0; $j < $nColumn; $j++) {
$value = $sheet->getCellByColumnAndRow($j, $i)->getValue();
if(!in_array($j,$notInResult)){
echo "$value";
}
}
It is necessary to remove certain columns from excel in the phpExcel library. Implemented in this way, can anyone tell me how to remove the bike?
Answer the question
In order to leave comments, you need to log in
You can come up with a dozen ways, but you got a fairly simple, readable and understandable code, I would leave it.
For example, here are the alternatives:
$notInResult = [0,1,2,4,5,7,8];
$all = range(0, $nColumn); //массив всех чисел от 0 до $nColumn
$inResult = array_diff($all, $notInResult); //убираем из массива всех чисел те, которые указаны в $notInResult
foreach ($inResult as $j) {
echo $sheet->getCellByColumnAndRow($j, $i)->getValue();
}
$notInResult = [0 => true, 1 => true, 2 => true, 4 => true, 5 => true, 7 => true, 8 => true]; //номера скрываемых колонок будем хранить в ключах массива, а значениями массива сделаем заглушку true
for ($j = 0; $j < $nColumn; $j++) {
if (!isset($notInResult[$j])) {
echo $sheet->getCellByColumnAndRow($j, $i)->getValue();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question