*/ $cemeteries = array(); foreach ($this->cemeteryList as $cemetery) { $name = addslashes($cemetery->getName()); $url = addslashes($cemetery->getURL()); $googleMapUrl = addslashes($cemetery->getGoogleMapURL()); $cemeteries[] = " { \"id\":\"{$cemetery->getId()}\", \"name\":\"$name\", \"url\":\"$url\", \"googleMapUrl\":\"$googleMapUrl\" } "; } $cemeteries = implode(',',$cemeteries); echo "[$cemeteries]";