簡體   English   中英

同時顯示具有相同鍵的數組的值

[英]Display values of array with the same key together

我有這個數組

[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在total.The第一標簽foreach獲取頂級數組的數組密鑰,但我怎么辦得到的值0,1,2,3的一個article ,例如,現在我只會有數組的兩個文章標簽?

您的意思是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM