I have some WordPress custom fields data that I am looping through and creating a comma separated string. The (small) issue is that I get a warning if I don't set the property as empty / null etc before looping.
I guess you can't concatenate a string if it doesn't yet exist. Although I get the warning, the foreach does what I need an there are no errors.
To stop the warning I have set the property as an empty string to start:
$memlog->postnominals = "";
foreach (get_field('post_nominals', $post->id) as $postnominal) {
$memlog->postnominals .= $postnominal->post_title . ", ";
}
Although not a big issue, I would rather know if there is a way I can do this without setting an empty string?