• 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?

Liam W

Well-known member
#1
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
 
S

Syndol

Guest
#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];
 

Liam W

Well-known member
#3
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