1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting a multidimensional array from input?

Discussion in 'XenForo Development Discussions' started by Liam W, Feb 2, 2014.

  1. Liam W

    Liam W Well-Known Member

    Is that possible?

    Currently, you can do:

    HTML:
    <input type="xx" name="n[]">
    <input type="xx" name="n[]">
    <input type="xx" name="n[]">
    and then:

    PHP:
    $data $this->_input->filter(array(
    'n' => array(XenForo_Input::STRING'array' => true)
    ));
    to get all of the set 'n' values.

    What if the form is like this?

    HTML:
    <input type="xx" name="n[data][]">
    <input type="xx" name="n[data][]">
    <input type="xx" name="n[data][]">
    Doing
    PHP:
    $data $this->_input->filter(array(
    'n' => array(XenForo_Input::STRING'array' => true
    ));
    only gives the first value, how would I get them all?

    Liam
     
  2. Syndol

    Syndol Guest

    In your example your array looks like this:
    Code:
    n[data][]
    So to fetch it you would do:
    PHP:
    $nArray $this->_input->filterSingle('n'XenForo_Input::ARRAY_SIMPLE);
    $data $nArray['data'];
    $x $data[0];
    $y $data[1];
    $z $data[2];
     
    Liam W likes this.
  3. Liam W

    Liam W Well-Known Member

    The issue with that is that the data isn't checked to see if it's the right type, although I guess it is the correct and only way :)

    Liam
     
  4. Jaxel

    Jaxel Well-Known Member

    I just use:
    Code:
    XenForo_Input::ARRAY_SIMPLE
     

Share This Page