Getting a multidimensional array from input?

Liam W

in memoriam 1998-2020
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
 
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];
 
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];

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
 
Back
Top Bottom