i found an issue in a webservice using php, i have an event(one record) in my db, that is for multiple days like,
2013-09-17 00:00:00 to 2013-09-20 23:59:59
for four days, i want to print it four times with four different date like ,
event_date = 2013-09-17 00:00:00
event_date = 2013-09-18 00:00:00
event_date = 2013-09-19 00:00:00
event_date = 2013-09-20 00:00:00
but it always prints the last date, i am looping to print json object four times, it works fine, but always prints the last date in each object,
My expected output shoud be,
{
"id": "472",
"event_date": "2013-09-17 00:00:00",
"event_type": "MULTIPLE_DAYS",
"multiple_days_start_date": "2013-09-17 00:00:00",
"multiple_days_end_date": "2013-09-20 23:59:59"
}, {
"id": "472",
"event_date": "2013-09-18 00:00:00",
"event_type": "MULTIPLE_DAYS",
"multiple_days_start_date": "2013-09-17 00:00:00",
"multiple_days_end_date": "2013-09-20 23:59:59"
}, {
"id": "472",
"event_date": "2013-09-19 00:00:00",
"event_type": "MULTIPLE_DAYS",
"multiple_days_start_date": "2013-09-17 00:00:00",
"multiple_days_end_date": "2013-09-20 23:59:59"
}, {
"id": "472",
"event_date": "2013-09-20 00:00:00",
"event_type": "MULTIPLE_DAYS",
"multiple_days_start_date": "2013-09-17 00:00:00",
"multiple_days_end_date": "2013-09-20 23:59:59"
},
here is my json object output,
{
"id": "1",
"event_date": "2013-09-19 00:00:00",
"event_type": "MULTIPLE_DAYS",
"multiple_days_start_date": "2013-09-17 00:00:00",
"multiple_days_end_date": "2013-09-20 23:59:59"
}
here is my code,
(foreach $events as $event)
if($event->event_type == 'MULTIPLE_DAYS') {
$mul_start_date = substr($event->multiple_days_start_date, 8,2);
$mul_end_date = substr($event->multiple_days_end_date, 8,2);
for($mul_start_date; $mul_start_date<=$mul_end_date;) {
$event->event_date = substr_replace($event->multiple_days_start_date, $mul_start_date, 8,2);
$events[] = $event;
$mul_start_date++;
}
}
echo json_encode($events);
Any help please,
$eventis an object, and its reference is stored in the array$events. Therefore, when the object is added to the array and the object is modified, all (same) other objects in the array seems to be modified. However, I don't know how to resolve this problem prettily... :(