Wondering if anyone can help with the following. Basically I have a form which allows users to select a start and end date, start time and end time.
The user can add time blocks, so they select the info they want, post it, then the page is returned, this happens until they process the form with the complete button.
The issue I am facing is, I need my array to append each post to my array, I have the following code:
if($this->input->post('submit', TRUE) == 'more')
{
$start_date = $this->input->post('start_date', TRUE);
$start_time = $this->input->post('start_time', TRUE);
$end_time = $this->input->post('end_time', TRUE);
$start_dates['start_date'] = $start_date;
$start_dates['start_time'] = $start_time;
$start_dates['end_time'] = $end_time;
if(isset($this->session->userdata['start_dates']) )
{
$merged = array_merge_recursive($start_dates, $this->session->userdata['start_dates']);
}
else
{
$merged = null;
$this->session->set_userdata('start_dates', $start_dates);
}
Problem is, each time we add a new time block one of the items in the array is overwritten.
The expected output for the array is:
Array
(
[start_date] => Array
(
[0] => 2012-08-31
[1] => 2012-08-29
)
[start_time] => Array
(
[0] => 08:00
[1] => 09:00
)
[end_time] => Array
(
[0] => 12:00
[1] => 17:00
)
)
Array key [1] is always overwritten in this case, if we add only two time blocks this would not be a problem – however the user needs to be able to add more than 2 blocks, total limit is up to user to a set limit we’ll specify later.
Could anyone help get the logic sorted out.
Thanks in advance.
Mark
You need to save the merged data into the session too and the array merge should apply to the stored array in session: