I have a form that allows users to enter a name and an associated date of birth.
The form allows users to dynamically add more names and date of births.
I would like to push this data to an associated array $_SESSION variable and then loop through it.
<form action="page.php">
<input type="text" name="child[0][name]" value="Name">
<input type="text" name="child[0][dob]" value="Date of Birth">
<input type="submit" value="Submit">
</form>
//trying to save the posted data to a SESSION
$_SESSION['children'] = [];
if (isset($_POST['child'])) {
foreach ($_POST['child'] as $value) {
array_push($_SESSION['children'], $value['name']);
array_push($_SESSION['children'], $value['dob']);
}
}
What would the loop from the SESSION look like to get my data to read:
Peter Smith born on 11/11/1900
Sally Smith born on 11/22/2222
When I print_r($_SESSION):
Array ( [0] => Peter Smith [1] => 11/11/1900 [2] => Sally Smith [3] => 11/22/2222 )
child[0]so that each can be grouped$_SESSION['children'] = $_POST['child']