I'm trying to write a function which appends a string to an existing string for error handling.
The output that I'm searching:
// Begin:
// message1
// message2
Currently I have:
$error = "Begin:";
function addError($message) {
$error .= "<br>" . $message;
}
addError("message1");
addError("message2");
echo $error;
// ----- Which outputs -----
// Begin:
I would assume that the code above does the same as:
$error = "Begin:";
$error .= "<br>" . "message1";
$error .= "<br>" . "message2";
echo $error;
// ----- Which outputs -----
// Begin:
// message1
// message2
But it doesn't seem to work. Could someone elaborate on the mistake(s) I'm making?