Array - Get names: Url and Caption

0

I have dynamic inputs with names my_image[url] and my_image[caption]

<input name="my_image[url]" type="hidden" value="<?php echo $imgurl['url'];?>"/>
<input name="my_image[caption]" type="text" value="<?php echo $imgurl['caption'];?>">

Even when inserting several images and captions dynamically, within isset $ _POST ['my_image'] is capturing only 1 image and 1 caption:

if (isset($_POST['my_image'])){ 
    update_option('imagens_inicio',array($_POST['my_image']);
    echo '<pre>'; var_dump($_POST['my_image']);echo '</pre>';
}

array(1) {
  [0]=>
  array(2) {
    ["url"]=>
    string(96) "http://localhost/theme/wp-content/uploads/2017/08/4e07dd2bd752b989e9b4687129982977.jpg"
    ["caption"]=>
    string(0) "test text"
  }
}

How do I make the array to be created in a continuous sequence:

url[]
caption[]
url[]
caption[]

Thank you for your help

    
asked by anonymous 01.09.2017 / 00:13

1 answer

0

With help on SOen , in the question I asked her too, and @Isac's help here from SOpt I solved:

 if (isset($_POST['url'])){ 

          $url = $_POST['url'];
          $caption = $_POST['caption'];

          $data = array_map(function ($url, $caption) {
                return compact('url', 'caption');
           }, $url, $caption);

           update_option('imagens_inicio',$data);

    }
    
01.09.2017 / 03:01