i trying create json object string. new php , should doing using arrays i'm not sure how nest arrays in loop. part of array i'm having problem creating array of dates. last date object shown after using json_encode
. if echo string, of dates there. @ first tried appending loop variable key , works out of order when brought ios apparently can't append loop variable. here code. or guidance appreciated.
date_default_timezone_set('america/los_angeles'); $timezone = date_default_timezone_get(); $date1 = new datetime($item['startdate']['s']); $date2 = new datetime($item['enddate']['s']); $date = new datetime(date('m/d/y')); $interval = dateinterval::createfromdatestring('1 day'); $period = new dateperiod($date, $interval, $date2); $to_time = date('h:i:s', strtotime($item['endtime']['s'])); $from_time = date('h:i:s a', time()); $loop = round(abs($to_time - $from_time)); $dv = 0; foreach ($period $dt) { if ($dv == 30) break; $spaces .= "\"dates\": {\"date\":\"" . $dt->format('m-d-y') . "\","; $spaces .= "\"timeslots\":{"; ($i = 0;$i <= $loop; $i++) { $spaces .= "\"timeslot" . $i . "\":\"" . date('h', time() + ($i*3600)) . ":00" . "\","; } $spaces = substr($spaces,0,-1); $spaces .= "}},"; $dv++; }
Comments
Post a Comment