I have Input fields that result in an array after POST:
<tr>
<td><input name="time['day'][]" value="1"></td>
<td><input name="time['from][]" value="1"></td>
<td><input name="time['to][]" value="1"></td>
</tr>
<tr>
<td><input name="time['day'][]" value="2"></td>
<td><input name="time['from][]" value="2"></td>
<td><input name="time['to][]" value="2"></td>
</tr>
This will be return:
Array (
['day'] => Array ( [0] => 1 [1] => 2 ) ['from] => Array ( [0] => 1 [1] => 2 ) ['to] => Array ( [0] => 1 [1] => 2 ))
But I would like to have this:
Array ( [1] => Array
( ['day'] => 1 ['from] => 1 ['to] => 1 ) [2] => Array ( ['day'] => 2 ['from] => 2 ['to] => 2 ))
I get this if I use:
<tr>
<td><input name="time[1]['day']" value="1"></td>
<td><input name="time[1]['from]" value="1"></td>
<td><input name="time[1]['to]" value="1"></td>
</tr>
<tr>
<td><input name="time[2]['day']" value="2"></td>
<td><input name="time[2]['from]" value="2"></td>
<td><input name="time[2]['to]" value="2"></td>
</tr>
But here comes the problem. I want to add new rows dynamicly (with JS) and would need to add always +1 to the first index.
How could I achive the second result without having to set the first index manually?
name="time[1][day]".$('input').attr('name').match(/\[(\d+)\]/)[1];