Use array_keys() and implode() where possible instead of foreach().