1

我不想发布这个,但我时间紧迫,需要一些帮助来访问这个庞大的多维数组中的值。熬夜后,我没有更多的脑力或耐力来玩它了。那么有人可以帮助我使用一组嵌套的 for 循环来获取这些值吗?!谢谢大家。

Array
(
    [0] => Array
        (
            [120] => Array
                (
                    [field_1_textbox_text] => Panel 1
                    [field_2_textbox_text] => p1
                    [field_3_wysiwyg_content] => Pane 1
                    [field_4_textbox_text] => P1
                )

        )

    [1] => Array
        (
            [121] => Array
                (
                    [field_1_textbox_text] => Panel 2
                    [field_2_textbox_text] => p2
                    [field_3_wysiwyg_content] => Panel 2
                    [field_4_textbox_text] => p2
                )

        )

    [2] => Array
        (
            [122] => Array
                (
                    [field_1_textbox_text] => Panel 3
                    [field_2_textbox_text] => p3
                    [field_3_wysiwyg_content] => panel 3333
                    [field_4_textbox_text] => p3
                )

        )

)
4

3 回答 3

2
foreach ($array as $key => $arr) {
    foreach ($arr as $key => $arr) {
        echo $key, PHP_EOL;
        foreach ($arr as $key => $value) {
            echo $key, ': ', $value, PHP_EOL;
        }
    }
}
于 2012-07-02T11:29:21.710 回答
1

没看懂问题。你认为 - $array[0][120]['field_1_textbox_text']?要不然是啥?每个维度都有一个循环。如果我有 2D 数组,我在其他 foreach 循环中有 foreach 循环。在 3D 数组中,您将在另一个 foreach 循环中的其他 fooreach 循环内有 foreach 循环。

于 2012-07-02T11:30:38.823 回答
0
/* foreach example 4: multi-dimensional arrays */
$a = array();
$a[0][0] = "a";
$a[0][1] = "b";
$a[1][0] = "y";
$a[1][1] = "z";

foreach ($a as $v1) {
  foreach ($v1 as $v2) {
    echo "$v2\n";
  }
}

阅读http://php.net/manual/en/control-structures.foreach.php或使用递归函数

于 2012-07-02T11:32:49.007 回答