我写了一个里面有很多东西的表格,然后使用 foreach 来获取信息。到目前为止,我的 foreach 运行良好,但如果我使用 foreach 之外的信息,我会得到一些奇怪的数据。
这是我的代码,只有 foreach 和数据提取:
foreach ($_POST['number3'] as $id1 => $array) {
foreach ($array as $id2 => $alpha) {
foreach ($alpha as $id3 => $gama) {
$_SESSION['number3'][$id1][$id2][$id3] = $gama;
echo 'The value of $_SESSION["'.$id1.'"]["'.$id2.'"] ["'.$id3.'"] is '."'".$gama."'".' <br />';
}
}
}
for ($i = 1; $i <= $_SESSION["number"]; $i++) {
echo "Numero ";
echo $i;
echo "<br />";
for ($j = 1; $j <= $_SESSION["number2_{$i}"]; $j++) {
echo "Letter ";
echo $j;
echo ": ";
for ($id = 0; $id <= $_SESSION["id"]; $id++) {
echo "value: ";
echo " ";
echo $_SESSION['number3'][$i][$j][$id];
}
echo "<br />";
}
}
通过我的 foreach 中的回声,我将获得如下数据:
The value of $_SESSION["1"]["1"] ["0"] is '13:01'
The value of $_SESSION["1"]["1"] ["1"] is '01:01'
The value of $_SESSION["1"]["1"] ["2"] is '1'
The value of $_SESSION["1"]["2"] ["0"] is '14:02'
The value of $_SESSION["1"]["2"] ["1"] is '02:02'
The value of $_SESSION["1"]["2"] ["2"] is '2'
The value of $_SESSION["1"]["3"] ["0"] is '15:03'
The value of $_SESSION["1"]["3"] ["1"] is '03:03'
The value of $_SESSION["1"]["3"] ["2"] is '3'
这就是我想要的,所以这里没有问题。但是当我执行 for 循环时,我得到了这个:
Numero 1
Letter 1: value: 13:01 value: 01:01 value: 1
Letter 2: value: 1 value: 0 value: 2
Letter 3: value: 15:03 value: 03:03 value: 3
对于字母 2,第 2 个值的数据是错误的,我不明白为什么,因为一切正常。你有什么建议吗?谢谢