Title: How to save array values in a widget
Last modified: August 20, 2016

---

# How to save array values in a widget

 *  [Mark Jansen](https://wordpress.org/support/users/mark-jansen/)
 * (@mark-jansen)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/how-to-save-array-values-in-a-widget/)
 * Ladies and gents,
 * I’m working on a widget and in that widget I want a few <select> fields and a
   few URL fields. In the example I’m going to give, you see the URL fields. I want
   to put those fields in an array and place that in the DB and read that same array
   out again.
 * I’m not sure what I’m doing wrong, but all the fields get the value ‘array’ now.
 *     ```
       <?php
       function form($instance) {
               $url = esc_attr($instance['url']);
               for($i=0;$i<5;$i++) {
               ?>
               <p>
                   <?php print_r($url); ?>
       			<label for="<?php echo $this->get_field_id('url'); ?>"><?php _e('URL:'); ?>
       				<input class="widefat" id="<?php echo $this->get_field_id('url'); ?>-<?php echo $i; ?>" name="<?php echo $this->get_field_name('url'); ?>[]" type="text" value="<?php echo $url; ?>" />
       			</label>
       		</p>
       	<?php
               }
               ?>
       ```
   
 *     ```
       <?php
       function update($new_instance,$old_instance) {
       		$instance = $old_instance;
   
               for($i=0;$i<5;$i++) {
                   $instance['url'] = esc_attr($new_instance['url']);
               }
   
       		return $instance;
       	}
       ?>
       ```
   
 * I hope some one can give me a shove in the right direction.
 * Thanks

 The topic ‘How to save array values in a widget’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * 0 replies
 * 1 participant
 * Last reply from: [Mark Jansen](https://wordpress.org/support/users/mark-jansen/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/how-to-save-array-values-in-a-widget/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
