PHP返回后停止HTML输出

I have a function that returns two values based on conditions, in the page that the function array is being called there is html below which outputs onto the screen:

function submitMessage($user) {
if (!$user) {
$a = "Message A";
$b = "Message B";
return array($a, $b);
}
else {
$a = "Message C";
$b = "Message D";
return array($a, $b);
}

On the page:

$message = submitMessage($username);

<div class="r-box box-shadow">
  <h4 class="text-center weight-700"><?php echo $message[0];?></h4>
    <p><?php echo $message[1];?></p>
</div>
//more html below etc

What I want is for the html output to stop after what is returned from the first part of the IF statement. Something like:

function submitMessage($user) {
if (!$user) {
$a = "Message A";
$b = "Message B";
return array($a, $b);
exit();
//would like the output to stop if this is met.
}
else {
$a = "Message C";
$b = "Message D";
return array($a, $b);
}

I tried adding the exit like above but the HTML still gets sent to the screen. Is it possible to stop the output of HTML if the first part is met?

<div class="r-box box-shadow">
  <h4 class="text-center weight-700"><?php echo $message[0];?></h4>
  <p><?php echo $message[1];?></p>
</div>
<?php  // if $message[1] is defined and not empty, exit
  if ((isset($message[1])) && (!empty($message[1]))){die();} ?>

//more html below etc

I'm not sure do I get you correctly but for that kind of stuff you can use PHP alternative syntax for control structures Other alternative to this would be to use Output buffering if you need to completely stop the output. Your function submitMessage returns before it reaches the exit(); part so exit is never executed. On the other hand if it did execute your would not have any output after that because the server would just stop executing the script.

Alternative sintax would be something like this

$message = submitMessage($username);
<?php if (!$user): ?>
<div class="r-box box-shadow">
<h4 class="text-center weight-700"><?php echo $message[0];?></h4>
<p><?php echo $message[1];?></p>
</div>
<?php else: ?>
some other html here
<?php endif; ?>