数组是当前3个子数组的深度。
以下是我正在使用的代码:
for ($tcid = 1; $tcid <= count($categories); $tcid++) {
$catHeader[$tcid] = $categories[$tcid][0];
$event[$i]['tickets'] = $categories;
unset($categories[$tcid][0]);
$categories[$tcid] = array_map('trim', $categories[$tcid]);
$categories[$tcid] = array_values($categories[$tcid]);
$ab = 0;
for ($b = 0; $b <= count($categories[$tcid]); $b++) {
if ($categories[$tcid][$b] == "" || !$categories[$tcid][$b] || $categories[$tcid][$b] == null) {
unset($categories[$tcid][$b]);
}
}
}
,数组看起来像......
[1] => Array (
[data] => Array ( ...
)
[tickets] => Array (
[1] => Array (
[0] => xxx
[1] => etc
[3] => etc2
)
[2] => (
[0] => Std1
[1] => 10 / 10
[2] => £20.00
[3] => £200.00
[4] => Std2
[5] => 100 / 100
[6] => £13.00
[7] => £1,300.00
[8] => Std3
[9] => 10 / 320
[10] => £15.00
[11] => £150.00
)
)
)
我今天向您提出的问题是,我是如何在每个4 \ n或数组键中分割数组,因为它们已知并将每个4分解为另一个子数组?
这样Std1,Std2,Std3将成为他们自己的子数组及其关联票据的第二个关键数据,但也会为每个具有多个数据集的一个子数组(一组数据)执行此操作是4个数组键。)
我尝试了各种各样但不能让它发挥作用。
请参阅下面我希望它的外观。
[1] => Array (
[data] => Array ( ...
)
[tickets] => Array (
[1] => Array (
[0] => xxx
[1] => etc
[3] => etc2
)
[2] => (
[0] => Array (
[0] => Std1
[1] => 10 / 10
[2] => £20.00
[3] => £200.00
)
[1] => Array (
[0] => Std2
[1] => 100 / 100
[2] => £13.00
[3] => £1,300.00
)
[2] => Array (
[0] => Std3
[1] => 10 / 320
[2] => £15.00
[3] => £150.00
)
)
)
)
由于
答案 0 :(得分:1)
正如评论中所述,您最好通过引用来处理数组,以便在循环中的某个位置修改它的原始内容
如果你想要块的数组分组是4
的组,你可以array_chunk()
:
$array['tickets'][2] = array_chunk($array['tickets'][2], 4);