Я хочу прочитать данные из файла excel по горизонтали и вертикали и расположить их в массиве, но у меня есть возможность создать массив в соответствии с приведенным ниже результатом / формат.
Array
(
[ZWL] => Array
(
[ZWL] => 1
[ZMW] => 2
[ZAR] => 3
[YER] => 4
[XPF] => 5
)
[ZMW] => Array
(
[ZWL] => 6
[ZMW] => 7
[ZAR] => 8
[YER] => 9
[XPF] => 10
)
[ZAR] => Array
(
[ZWL] => 11
[ZMW] => 12
[ZAR] => 13
[YER] => 14
[XPF] => 15
)
[YER] => Array
(
[ZWL] => 16
[ZMW] => 17
[ZAR] => 18
[YER] => 19
[XPF] => 20
)
[XPF] => Array
(
[ZWL] => 21
[ZMW] => 22
[ZAR] => 23
[YER] => 24
[XPF] => 25
)
[XOF] => Array
(
[ZWL] => 26
[ZMW] => 27
[ZAR] => 28
[YER] => 29
[XPF] => 30
)
[XCD] => Array
(
[ZWL] => 31
[ZMW] => 32
[ZAR] => 33
[YER] => 34
[XPF] => 35
)
[XAF] => Array
(
[ZWL] => 36
[ZMW] => 37
[ZAR] => 38
[YER] => 39
[XPF] => 40
)
[WST] => Array
(
[ZWL] => 41
[ZMW] => 42
[ZAR] => 43
[YER] => 44
[XPF] => 45
)
)
Ниже приведен код, который я пробовал.
<code><?php
require_once ('SimpleXLSX.php');
if ($xlsx = SimpleXLSX::parse('test.xlsx')) {
$Arr = array();
$count = 0;
$i = 0;
$WithoutHeader = $xlsx->rows();
unset($WithoutHeader[0]);
$totalRowInColumn = $xlsx->dimension()[1];
foreach ($xlsx->rows()[0] as $key => $val) {
if ($key != 0 && $key != 1) {
for ($i = 1; $i < $totalRowInColumn; $i++) {
for ($j = 1; $j < $totalRowInColumn; $j++) {
$Arr[$val][$WithoutHeader[$j][$i]] = 'val';
}
}
}
}
echo '<pre>';
print_r($Arr);
echo '
';} else {echo SimpleXLSX :: parseError ();} function pr ($ data) {echo "
";
print_r($data);
echo "
";}
Пример кода
https://repl.it/repls/GrizzledAdventurousMicrokernel
Формат Excel
Мой токовый выход
Array
(
[ZWL] => Array
(
[ZWL] => val
[ZMW] => val
[ZAR] => val
[YER] => val
[XPF] => val
[1] => val
[2] => val
[3] => val
[4] => val
[5] => val
[6] => val
[7] => val
[8] => val
[9] => val
[10] => val
[11] => val
[12] => val
[13] => val
[14] => val
[15] => val
[16] => val
[17] => val
[18] => val
[19] => val
[20] => val
)
[ZMW] => Array
(
[ZWL] => val
[ZMW] => val
[ZAR] => val
[YER] => val
[XPF] => val
[1] => val
[2] => val
[3] => val
[4] => val
[5] => val
[6] => val
[7] => val
[8] => val
[9] => val
[10] => val
[11] => val
[12] => val
[13] => val
[14] => val
[15] => val
[16] => val
[17] => val
[18] => val
[19] => val
[20] => val
)
[ZAR] => Array
(
[ZWL] => val
[ZMW] => val
[ZAR] => val
[YER] => val
[XPF] => val
[1] => val
[2] => val
[3] => val
[4] => val
[5] => val
[6] => val
[7] => val
[8] => val
[9] => val
[10] => val
[11] => val
[12] => val
[13] => val
[14] => val
[15] => val
[16] => val
[17] => val
[18] => val
[19] => val
[20] => val
)
[YER] => Array
(
[ZWL] => val
[ZMW] => val
[ZAR] => val
[YER] => val
[XPF] => val
[1] => val
[2] => val
[3] => val
[4] => val
[5] => val
[6] => val
[7] => val
[8] => val
[9] => val
[10] => val
[11] => val
[12] => val
[13] => val
[14] => val
[15] => val
[16] => val
[17] => val
[18] => val
[19] => val
[20] => val
)
[XPF] => Array
(
[ZWL] => val
[ZMW] => val
[ZAR] => val
[YER] => val
[XPF] => val
[1] => val
[2] => val
[3] => val
[4] => val
[5] => val
[6] => val
[7] => val
[8] => val
[9] => val
[10] => val
[11] => val
[12] => val
[13] => val
[14] => val
[15] => val
[16] => val
[17] => val
[18] => val
[19] => val
[20] => val
)
[XOF] => Array
(
[ZWL] => val
[ZMW] => val
[ZAR] => val
[YER] => val
[XPF] => val
[1] => val
[2] => val
[3] => val
[4] => val
[5] => val
[6] => val
[7] => val
[8] => val
[9] => val
[10] => val
[11] => val
[12] => val
[13] => val
[14] => val
[15] => val
[16] => val
[17] => val
[18] => val
[19] => val
[20] => val
)
[XCD] => Array
(
[ZWL] => val
[ZMW] => val
[ZAR] => val
[YER] => val
[XPF] => val
[1] => val
[2] => val
[3] => val
[4] => val
[5] => val
[6] => val
[7] => val
[8] => val
[9] => val
[10] => val
[11] => val
[12] => val
[13] => val
[14] => val
[15] => val
[16] => val
[17] => val
[18] => val
[19] => val
[20] => val
)
[XAF] => Array
(
[ZWL] => val
[ZMW] => val
[ZAR] => val
[YER] => val
[XPF] => val
[1] => val
[2] => val
[3] => val
[4] => val
[5] => val
[6] => val
[7] => val
[8] => val
[9] => val
[10] => val
[11] => val
[12] => val
[13] => val
[14] => val
[15] => val
[16] => val
[17] => val
[18] => val
[19] => val
[20] => val
)
[WST] => Array
(
[ZWL] => val
[ZMW] => val
[ZAR] => val
[YER] => val
[XPF] => val
[1] => val
[2] => val
[3] => val
[4] => val
[5] => val
[6] => val
[7] => val
[8] => val
[9] => val
[10] => val
[11] => val
[12] => val
[13] => val
[14] => val
[15] => val
[16] => val
[17] => val
[18] => val
[19] => val
[20] => val
)
)