I have:
<form action="save.php" method="POST">
<input type="text" name="test[one][]" value="a"><input type="text" name="test[two][]" value="a"> <br />
<input type="text" name="test[one][]" value="s"><input type="text" name="test[two][]" value="s"><br />
<input type="text" name="test[one][]" value="d"><input type="text" name="test[two][]" value="d"><br />
<input type="text" name="test[one][]" value="f"><input type="text" name="test[two][]" value="f"><br />
<input type="text" name="test[one][]" value="g"><input type="text" name="test[two][]" value="g"><br />
<input type="submit">
</form>
In database are:
Table:
id | one | two
in PHP i would like make:
if($_POST){
foreach($_POST['test'] as $post){
$new = new Table();
$new->setOne($post['one']);
$new->setTwo($post['two']);
$new->save();
}
}
But this not working… I can’t use POST for index ‘one’ and ‘two’ – i must use two loop foreach. Is possible to make with one foreach or foreach in foreach?
print_r($_POST) return me:
[test] => Array ( [one] => Array ( [0] => a [1] => s [2] => d [3] => f [4] => g ) [two] => Array ( [0] => a [1] => s [2] => d [3] => f [4] => g ) ) )
I would go this way: