I require a json output in the sample format:
[ { "date": "2013-04-01 17:30:00", "type": "meeting", "title": "Test Last Year", "description": "Lorem Ipsum dolor set", "url": "http://test.com?id=1" }, { "date": "2013-04-02 17:30:00", "type": "meeting", "title": "Test Last Year", "description": "Lorem Ipsum dolor set", "url": "http://test.com?id=2" } }]
The last comma needs to be stripped out after : "http://test.com?id=2" } , }] to create a json out put without error. I am using php and here is the relevant portion of my php code: (slightly changed to display only relevant portion)
echo '[';
foreach ($enquirydates as $edate)
{
if ($x <= $firstunixdate )//first follow-up
{
echo ' { "date": "'; echo date("Y-m-d ", $firstunixdate); echo '", "type": "Follow-up", "title": "Student Enquiry '; echo ' Follow-up (First Follow-Up)", "description": "First Student Enquiry followup due..", "url": "http://test.com/admin/followup.php?time=';echo $unixenquirydate; echo '" },';
}
elseif ($x <= $secondunixdate)//second followup
{
echo ' { "date": "'; echo date("Y-m-d ",$secondunixdate); echo '", "type": "Follow-up", "title": "Student Enquiry '; echo ' Follow-up (Second Follow-Up)", "description": "Second Student Enquiry followup due..", "url": "http://test.com/admin/followup.php?time=';echo $unixenquirydate; echo '"},';
}
elseif ($x > $finalunixdate)//enquiry open for more than 25 days
{
echo ' { "date": "'; echo date("Y-m-d ",$x); echo '", "type": "Follow-up", "title": "Student Enquiry '; echo ' open for more than 25 days", "description": "Second Student Enquiry followup due..", "url": "http://test.com/admin/followup.php?time=';echo $unixenquirydate; echo '"},';
}//end if
}
echo ']';
I need to remove the last comma in the foreach loop. I know that implode can be used to remove ending strings in php. But I am lost on how to use it in this context (multiple echo statements)
Requesting help..