-2

Please help. I've come across an input field like this and it is confusing me:

<input type="text" name="filter[][isranged][]">

I know it has to do with an array, but does this even make sense leaving the first and third bracket sets empty? The brackets deal with creating keys for the values and what I was thinking is that this "filter" is an array that has another array in it (with a key called isranged) which has another array inside it. Am I correct? The brackets are confusing me.

The input is used to store a date like this: 09/03/2014

Malbert
  • 3
  • 2

2 Answers2

1

The [] is used to dynamically create the next element 0, 1, etc. Given two inputs named like that you will get the following $_POST array:

Array
(
    [filter] => Array
        (
            [0] => Array
                (
                    [isranged] => Array
                        (
                            [0] => 'Value of first input'
                        )

                )

            [1] => Array
                (
                    [isranged] => Array
                        (
                            [0] => 'Value of second input'
                        )

                )

        )

)

[filter] gets a new numeric index for each input but the [isranged] array will always only contain 1 element [0] since they are part of different filter[x] arrays.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
  • Thank you everyone this helped a bunch. So since it is an input the value inputted would be stored on the "inner" array at position [0] right? @AbraCadaver – Malbert Sep 03 '14 at 17:32
  • For each input it would be stored at `$_POST['filter'][x]['isranged'][0]` where `x` is the index of `filter` and unique for each input. Edit to show input value. – AbraCadaver Sep 03 '14 at 17:39
-1

If you were to break that structure down into logical form it would be

filter = [
    { isranged: [ Many Values ] }
]

So basically filter is an array of an object that has a property of "isranged" that is an array itself.

Justin Workman
  • 380
  • 3
  • 6