Support

Account

Home Forums General Issues How to use Text Field or Text Area to create an array?

Helping

How to use Text Field or Text Area to create an array?

  • Hi,

    I need to be able to type multiple values into a text field and for those values to be stored as an array for the field. I can do this with the “Select” field, but that assumes you know in advance what information will be entered in – how can I do this without knowing what data will be entered beforehand? Thanks.

  • Hey, late response, but try this:

    $text_area = get_field("text_area");
    $text_area_arr = explode("\n", $text_area);
    $text_area_arr = array_map('trim', $text_area_arr);

    If you put each value on a new line in the text area, then $text_area_arr should be an array with each new line value. array_map is to get rid of extra white space.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to use Text Field or Text Area to create an array?’ is closed to new replies.