$data =([01] => 0 [02] => 0 [03] => 1 [04] => 0 [05] => 0 [06] => 0
[07] => 0 [08] => 0 [09] => 1 [10] => 0 [11] => 0 [12] => 0
[13] => 0 [14] => 0 [15] => 0 [16] => 0 [17] => 0 [18] => 0
[19] => 0 [20] => 0 [21] => 0 [22] => 0 [23] => 0 [24] => 0
[25] => 0 [26] => 0 [27] => 0 [28] => 0 [29] => 0 [30] => 0
[31] => 0)
期待輸出:如何將數組值分爲3列?
0=>([01]=>0 [11]=>0 [21]=>0)
1=>([02]=>0 [12]=>0 [22]=>0)
2=>([03]=>0 [13]=>0 [23]=>0)
upto
10=>([10]=>0 [20]=>0 [30]=>0)
這是我的當前代碼嘗試:
foreach ($data as $k => $v) {
for ($i=0; $i<10;$i++){
if ($k <= 10) { $one[$k] = $v; }
elseif($k>10 && $k<=20) { $two[$k]=[$v]; }
else { $three[$k] = $v; }
}
}
我已經使用關聯數組概念(具有鍵和值),已予有分裂從單個數組到3個數組,但我得到的結果像(1到10),(11-20)和(21-30),而不是我想要的(1-11-21)(2-12-22)。
你的問題是相當混亂,很難理解。第一個預期的輸出有索引0和第一個值1,第10個預期的輸出有索引10和第一個值10 ...那裏已經有些問題了,我想...... – Julo0sS