I want to build a string like this: ["Badin","Bahawalnagar","Bahawalpur"]
but when I run my script I get an extra comma in the last iteration.
if ($result->num_rows() > 0)
{
echo '[';
foreach($result->result() as $listing)
{
echo '"'.$listing->city_name.'"';
if ($listing->city_name!='')
{
echo ',';
}
}
echo ']';
}
I want to remove the last comma inside the closing brace.
["Badin","Bahawalnagar","Bahawalpur",]