formatOutput = true; $courses=$doc->appendChild($doc->createElement('courses')); $previous=$courses->appendChild($doc->createElement('previous')); $following=$courses->appendChild($doc->createElement('following')); if (!empty($bookings)) { foreach($bookings as $stamp=>$booking) { if ($stamp<$time){ $course=$previous->appendChild($doc->createElement('course')); $course->appendChild($doc->createElement('group',implode(',',$booking['group']))); $course->appendChild($doc->createElement('courseId',implode(',',$booking['course']))); $course->appendChild($doc->createElement('title',$booking['title'])); $course->appendChild($doc->createElement('teacher',$booking['teacher'])); $course->appendChild($doc->createElement('starttime',$booking['starttime'])); $course->appendChild($doc->createElement('endtime',$booking['endtime'])); $course->appendChild($doc->createElement('duration',$booking['duration'])); } else { $course=$following->appendChild($doc->createElement('course')); $course->appendChild($doc->createElement('group',implode(',',$booking['group']))); $course->appendChild($doc->createElement('courseId',implode(',',$booking['course']))); $course->appendChild($doc->createElement('title',$booking['title'])); $course->appendChild($doc->createElement('teacher',$booking['teacher'])); $course->appendChild($doc->createElement('starttime',$booking['starttime'])); $course->appendChild($doc->createElement('endtime',$booking['endtime'])); $course->appendChild($doc->createElement('duration',$booking['duration'])); } } } echo $doc->saveXML(); ?>