Two PHP Values in Array

I have a value from a option field:

The value being pulled from the data base looks like this $value = $this->value;.

Read More

Then I can update the value like this:

<textarea id="'.$this->field['id'].'[]" name="'.$this->args['opt_name'].'['.$this->field['id'].'][]" rows="6" class="'.$class.'" />'.esc_attr($value).'</textarea>

What I want to do is to add another text area field below the first one, and for it to save both values in the database. I can copy and paste the above code, and it updates my array. But the values don’t show inside the field itself, the field is empty. Any clue on what I should do?

Related posts

Leave a Reply

1 comment

  1. Thanks for the feedback,

    I used array_chunk to fix my problem

    if(isset($this->value) {
    $chunk = array_chunk($value,2);
    
    foreach($chunk as $k => $value){
    
    <textarea id="'.$this->field['id'].'[]" name="'.$this->args['opt_name'].'['.$this->field['id'].'][]" rows="6" class="'.$class.'" >'.esc_attr($value[0]).'</textarea>
    
    <textarea id="'.$this->field['id'].'[]" name="'.$this->args['opt_name'].'['.$this->field['id'].'][]" rows="6" class="'.$class.'" >'.esc_attr($value[1]).'</textarea>
    
    }
    
    } else {
    
    <textarea id="'.$this->field['id'].'[]" name="'.$this->args['opt_name'].'['.$this->field['id'].'][]" rows="6" class="'.$class.'" >'.esc_attr($value).'</textarea>
    
    <textarea id="'.$this->field['id'].'[]" name="'.$this->args['opt_name'].'['.$this->field['id'].'][]" rows="6" class="'.$class.'" >'.esc_attr($value).'</textarea>
    
    }