通过多维数组PHP迭代

时间:2014-04-28 09:53:36

标签: php arrays

我有以下存储在$ _SESSION中的数组,我想通过它来显示数组下面所示格式的值:

    Array
(
[step_one] => Array
    (
        [width-ft] => 2
        [width-in] => 0
        [height-ft] => 2
        [height-in] => 0
    )

[step_two] => Array
    (
        [range] => penshaw
    )

[step_three] => Array
    (
        [style] => arch
    )

[step_four] => Array
    (
        [detail] => double bow
    )

[step_five] => Array
    (
        [decor] => circle
    )

[step_six] => Array
    (
        [basket] => round collar
    )

[step_seven] => Array
    (
        [finial] => spear
    )

)

现在如何迭代这样的值:

 width-ft: 2
 width-in: 0
 height-ft: 2
 height-in: 0

 range: penshaw
 style: arch
 detail: double bow
 decor: circle
 basket: round collar
 finial: spear

由于

1 个答案:

答案 0 :(得分:0)

<?php 
foreach($array as $stepArray) {
  foreach($stepArray as $key => $value) {
       echo $key.": ".$value;
  }
}
?>