同时显示具有相同键的数组的值 [英] Display values of array with the same key together

查看:40
本文介绍了同时显示具有相同键的数组的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个数组

[multiv] => Array
        (
            [31603] => Array
                (
                    [0] => one
                    [1] => two
                    [2] => three
                    [3] => four
                )

            [18992] => Array
                (
                    [0] => five
                    [1] => six
                    [2] => seven
                    [3] => eight
                )

        )

我想使用文章一起显示其所有元素和每个数组键标签。我有这个

which i want to display all its elements and every array key together using an article tag.I have this

  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>
        ";
     }
  }

,但问题是代码总共输出八个 article 标签。第一个 foreach 获取顶部数组的数组键,但是我该怎么做在一个 article 中获得值 0,1,2,3 ,这样现在我将只有两个article标签

but the problem is the code outputs eight article tags in total.The first foreach gets the array keys of the top array but how do i do to get the values 0,1,2,3 in one article such that now i will only have two article tags for the array?.

推荐答案

您的意思是:

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

这篇关于同时显示具有相同键的数组的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆