Answer the question
In order to leave comments, you need to log in
How to traverse two arrays at the same time?
I am new to PHP. I am doing my import/export of Excel data. I have a nested array with data like this:
Array
(
[0] => Array
(
[number] => 1
[full_name] => Иванов Иван Иванович
[date] => 1995:07:02
[adress] => г. Москва
[passport] => ВС212928
[childs] => да
[salary] => 15,000.00 ₽
)
[1] => Array
(
[number] => 2
[full_name] => Петров Петр Петрович
[date] => 1993:01:01
[adress] => г. Москва
[passport] => АС212121
[childs] => нет
[salary] => 20,000.00 ₽
)
[2] => Array
(
[number] => 3
[full_name] => Сидоров Николай Николеевич
[date] => 1994:02:05
[adress] => г. Москва
[passport] => ВК199894
[childs] => да
[salary] => 1,200,000.00 ₽
)
}
foreach ($rows as $row) {
$active_sheet->setCellValue('A' . $count, $row['number']);
$active_sheet->setCellValue('B' . $count, $row['full_name']);
$active_sheet->setCellValue('C' . $count, $row['date']);
$active_sheet->setCellValue('D' . $count, $row['adress']);
$active_sheet->setCellValue('E' . $count, $row['passport']);
$active_sheet->setCellValue('F' . $count, $row['childs']);
$active_sheet->setCellValue('G' . $count, $row['salary']);
$count = $count + 1;
}
$alphabet = range('A','Z')
foreach ($rows as $key => $row) {
$active_sheet->setCellValue($alphabet[$key] . $count, $row[$key]);
$count = $count + 1;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question