我想将下面的数组拆分成3个单独的数组。但是,阵列的大小可以是任何数字。以下数组大小为3。
Array (
[0] => Array
(
[0] => a
[1] => bb
[2] => c
[3] => dd
[4] => ee
)
[1] => Array
(
[0] => dd
[1] => ff
[2] => hh
[3] => iji
[4] => kkk
[5] => a
[6] => cc
)
[2] => Array
(
[0] => ee
[1] => kk
[2] => iji
[3] => a
[4] => bb
[5] => lmn
[6] => ppq
[7] => xyz
)
)
预期产出:
Array1 (
[0] => a
[1] => bb
[2] => c
[3] => dd
[4] => ee
)
Array2 (
[0] => dd
[1] => ff
[2] => hh
[3] => iji
[4] => kkk
[5] => a
[6] => cc
)
Array3 (
[0] => ee
[1] => kk
[2] => iji
[3] => a
[4] => bb
[5] => lmn
[6] => ppq
[7] => xyz
)
单个数组的名称后面应跟一个为每个数组递增的数字。
答案 0 :(得分:2)
您可以使用list()
将3d数组拆分为3个单独的数组。
list($array1, $array2, $array3) = $mainArray;
以下是一个例子:https://3v4l.org/hQ1Te
现在,如果你不知道输入数组中有多少个数组,你可以这样做......
for($i=0; $i<count($mainArray); $i++){
$variableName = "array$i";
$$variableName = $mainArray[$i];
}
var_dump($array1, $array2, $array3, $array4, ...);
答案 1 :(得分:1)
所以你在找这样的东西吗?
edittype: "textarea"
编辑:好了,现在我明白了,你想要:
for ($i = 0; $i < count($inputArray); $i++) {
echo "Array ". $i;
echo "<pre>";
print_r($inputArray[$i]);
echo "</pre>";
}