Display array values ​​with the same key together

I have this array

[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 each key array together using a tag article

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

      

but the problem is that the code outputs eight tags article

. The first one foreach

gets the keys of the array of the top array, but how do I get the values 0,1,2,3

in one article

, that now I only have two article tags for the array ?.

0


source to share


1 answer


you mean:



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

      

+3


source







All Articles