0

Simply i want to upload some product images with thumbnail, thumbnail size, thumbnail Hd thumbnail Hd size

(thumbnail, thumbnail size, thumbnail Hd thumbnail Hd size) this hole think will be construct a single product image and i can upload multiple images. that's why i am using the below markup (as example).

<tr>
    <td>Thumbnail<input type="text" name="images[single_image][thumbnail][]" id=""></td>
    <td>Thumbnail Size<input type="text" name="images[single_image][thumbnail_size][]" id=""></td>
    <td>Thumbnail Hd<input type="text" name="images[single_image][Thumbnail_hd][]" id=""></td>
    <td>Thumbnail Hd Size<input type="text" name="images[single_image][thumbnail_hd_size][]" id=""></td>
</tr>

<tr>
    <td>Thumbnail<input type="text" name="images[single_image][thumbnail][]" id=""></td>
    <td>Thumbnail Size<input type="text" name="images[single_image][thumbnail_size][]" id=""></td>
    <td>Thumbnail Hd<input type="text" name="images[single_image][Thumbnail_hd][]" id=""></td>
    <td>Thumbnail Hd Size<input type="text" name="images[single_image][thumbnail_hd_size][]" id=""></td>
</tr>

after posting the data in php i am get the images array something like below

"images" => array:1 [▼
    "single_image" => array:4 [▼
      "thumbnail" => array:2 [▼
        0 => "Thumbnail One"
        1 => "Thumbnail Two"
      ]
      "thumbnail_size" => array:2 [▼
        0 => "Thumbnail One Size"
        1 => "Thumbnail Two Size"
      ]
      "Thumbnail_hd" => array:2 [▼
        0 => "Thumbnail One Hd"
        1 => "Thumbnail Two Hd"
      ]
      "thumbnail_hd_size" => array:2 [▼
        0 => "Thumbnail One Hd size"
        1 => "Thumbnail Two Hd size"
      ]
    ]
  ]

but i don't want that, what i want is this below images array because (thumbnail, thumbnail size, thumbnail Hd thumbnail Hd size) they are belongs to each other.

$images = [
    "single_image" => [
        "thumbnail" => "Thumbnail One",
        "thumbnail_size" => "Thumbnail One Size",
        "thumbnail_hd" => "Thumbnail One Hd",
        "thumbnail_hd_size" => "Thumbnail One Hd",
        "thumbnail_hd_size" => "Thumbnail One Hd Size",
    ],
    "single_image" => [
        "thumbnail" => "Thumbnail Two",
        "thumbnail_size" => "Thumbnail Two Size",
        "thumbnail_hd" => "Thumbnail Two Hd",
        "thumbnail_hd_size" => "Thumbnail Two Hd",
        "thumbnail_hd_size" => "Thumbnail Two Hd Size",
    ]
]

Now How i can achieve the above array in HTML or if it is not possible to achieve in html; How i can achieve in PHP with array function

kundefine
  • 83
  • 10
  • sorry @showdev, before complete the post it was submitted by accident. now I, added the complete problem. pls take a look. – kundefine Jul 20 '19 at 05:42
  • Thanks for the edit! You could use a numeric index in the input names, like [this](https://stackoverflow.com/a/12557334/924299). Or restructure the array with PHP, like [this](https://stackoverflow.com/a/4709991/924299). – showdev Jul 20 '19 at 05:44
  • Thanks man numeric index works perfectly. – kundefine Jul 20 '19 at 05:54
  • Possible duplicate of [How can I group form elements](https://stackoverflow.com/questions/5802057/how-can-i-group-form-elements) or [How to create an array of a group of items inside an HTML form](https://stackoverflow.com/questions/4100786/how-to-create-an-array-of-a-group-of-items-inside-an-html-form) or [How to split POST array in groups?](https://stackoverflow.com/questions/17799375/how-to-split-post-array-in-groups). – showdev Jul 20 '19 at 06:02

0 Answers0