我有这个数组
[multiv] => Array
(
[31603] => Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)
[18992] => Array
(
[0] => five
[1] => six
[2] => seven
[3] => eight
)
)
我希望使用article
标记将所有元素和每个数组键显示在一起。我有这个
foreach( $main_array['multiv'] as $key => $value ) {
foreach( $value as $k => $v ) {
echo "
<article class='crud_list'>
<input type='hidden' name='$key' />
<input type='text' name='$k' value='$v' /><br/>
<input type='checkbox' name='$k' value='$v' /><br/>
<input type='radio' name='$k' value='$v' /><br/>
<select><option>$k</option></select><br/>
</article>
";
}
}
但问题是代码总共输出了8个article
标记。第一个foreach
获取顶部数组的数组键但是如何获取值0,1,2,3
in一个article
,现在我只有两个文章标签?
答案 0 :(得分:3)
foreach($main_array['multiv'] as $key=>$value){
//add your article tag
echo "<article class='crud_list'>";
foreach($value as $k=>$v){
//add your inputs
echo "<input type='hidden' name='$key' />";
//rest of input
}
echo "</article>";
} // end of first foreach