Итак, я попытался использовать array_slice и либо не знаю, что с ним делать, либо мне нужно другое решение. У меня есть этот длинный массив, который возвращается из базы данных. Мне нужно разбить его на меньшие массивы из шести последовательных элементов, чтобы применять правильные цены с правильными товарами. Я понимаю, что нет данных во многих элементах массива. Все в порядке. Те, где нет цены на определенный размер с конкретным товаром.
Если кто-то может указать мне правильное направление, это будет очень цениться. Вот мой массив из print_r.
Array ( [0] => [1] => [2] => [3] => 761 [4] => [5] => [6] => [7] => [8] => [9] => [10] => 823 [11] => 937 [12] => [13] => [14] => [15] => 701 [16] => [17] => [18] => [19] => [20] => [21] => [22] => 745 [23] => 854 [24] => [25] => [26] => [27] => 735 [28] => [29] => [30] => [31] => [32] => [33] => [34] => 985 [35] => 1067 [36] => [37] => [38] => [39] => 655 [40] => [41] => [42] => [43] => [44] => [45] => 658 [46] => [47] => [48] => [49] => [50] => [51] => [52] => 701 [53] => 807 [54] => [55] => [56] => [57] => 692 [58] => [59] => [60] => [61] => [62] => [63] => [64] => [65] => 1020 [66] => [67] => [68] => 1039 [69] => [70] => 1099 [71] => [72] => [73] => [74] => 1029 [75] => [76] => 1149 [77] => [78] => 659 [79] => 664 [80] => [81] => [82] => [83] => [84] => 714 [85] => [86] => [87] => [88] => [89] => [90] => [91] => 724 [92] => 724 [93] => 739 [94] => 759 [95] => [96] => [97] => [98] => [99] => [100] => 989 [101] => [102] => 599 [103] => [104] => [105] => [106] => [107] => [108] => [109] => 679 [110] => 674 [111] => 669 [112] => 689 [113] => [114] => [115] => [116] => [117] => [118] => 899 [119] => [120] => 599 [121] => [122] => [123] => [124] => [125] => [126] => [127] => 614 [128] => 609 [129] => 639 [130] => 634 [131] => [132] => [133] => [134] => [135] => [136] => 834 [137] => [138] => 584 [139] => [140] => [141] => [142] => [143] => [144] => [145] => 652 [146] => 659 [147] => 644 [148] => 649 [149] => [150] => [151] => [152] => [153] => [154] => 829 [155] => [156] => 674 [157] => [158] => [159] => [160] => [161] => [162] => [163] => 659 [164] => 774 [165] => 679 [166] => 719 [167] => 969 [168] => [169] => [170] => [171] => [172] => 994 [173] => [174] => [175] => [176] => [177] => 1100 [178] => [179] => [180] => [181] => [182] => [183] => [184] => 1215 [185] => [186] => [187] => [188] => [189] => [190] => [191] => 1334 [192] => [193] => [194] => [195] => 825 [196] => [197] => [198] => [199] => [200] => [201] => [202] => 898 [203] => 1045 [204] => [205] => [206] => [207] => 915 [208] => [209] => [210] => [211] => [212] => [213] => [214] => 1012 [215] => [216] => [217] => [218] => [219] => [220] => [221] => 1174 [222] => [223] => [224] => [225] => 963 [226] => [227] => 1224 [228] => [229] => [230] => [231] => 944 [232] => [233] => 1222 [234] => [235] => [236] => [237] => 819 [238] => [239] => [240] => [241] => [242] => [243] => 822 [244] => [245] => [246] => [247] => [248] => [249] => [250] => 891 [251] => 1016 [252] => [253] => [254] => [255] => 856 [256] => [257] => [258] => [259] => [260] => [261] => [262] => 1131 [263] => 1229 [264] => [265] => [266] => [267] => [268] => [269] => 1234 [270] => 972 [271] => [272] => [273] => [274] => [275] => [276] => [277] => [278] => 982 [279] => [280] => 1017 [281] => [282] => [283] => 937 [284] => 932 [285] => [286] => 947 [287] => [288] => 857 [289] => [290] => [291] => [292] => [293] => [294] => [295] => [296] => 867 [297] => [298] => 892 [299] => [300] => [301] => [302] => 917 [303] => [304] => 907 [305] => [306] => [307] => [308] => 1032 [309] => [310] => 977 [311] => [312] => [313] => [314] => [315] => [316] => 1307 [317] => [318] => [319] => [320] => [321] => [322] => 1182 [323] => [324] => [325] => [326] => [327] => [328] => 1322 [329] => [330] => [331] => [332] => [333] => 1019 [334] => [335] => [336] => [337] => [338] => [339] => [340] => [341] => 1265 [342] => [343] => [344] => [345] => 1019 [346] => [347] => [348] => [349] => [350] => [351] => [352] => 1093 [353] => 1265 )
Это должно работать для вас:
<?php
//As an example
$array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
//Splits the array into groups of 6
$array = array_chunk($array, 6);
print_r($array);
?>
Выход:
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
[1] => Array
(
[0] => 7
[1] => 8
[2] => 9
[3] => 10
[4] => 11
[5] => 12
)
)
Других решений пока нет …